Using SObjectAccessDecision Class to Call one apex method from another method with two different controller and Passing multiple parameters value from one function to another and displaying cross object related record in lightning component Salesforce | calling multiple apex method and showing data from inner (Nested) soql query in lightning component Salesforce

1,558 views


Hey guys, today in this post we are going to learn about How to Use SObjectAccessDecision Class to Call one apex method from another method with two different controller and Passing multiple parameters value from one function to another and displaying cross object related record in lightning component Salesforce.

What is SObjectAccessDecision Methods in Salesforce

Contains the results of a call to the Security.stripInaccessible method and methods to retrieve those results.

Find the following are methods for SObjectAccessDecision.

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   
  • getModifiedIndexes()
    Returns the indexes of sObjects that are modified by the stripInaccessible method.
  • getRecords()
    Returns a list of new sObjects that are identical to the source records, except that they are stripped of fields that fail the field-level security check for the current user.
  • getRemovedFields()
    Returns a map of sObject types to their corresponding inaccessible fields. The map key is a string representation of the sObject type. The map value is a set of strings, which denote the fields names that are inaccessible.

➑ To know more details about SObjectAccessDecision Methods, Click Here

Real time scenarios:- Call multiple apex method Uses of SObjectAccessDecision Class (decision) and display data from inner (Nested) soql query (Opportunity and Report_Cards__c) sObject if Opportunity StageName will be match as “Needs Analysis” in Salesforce.

Files we used to Call Multiple Apex Methods in aura component controller in Salesforce

crossMethodCmp.cmp Lightning Component It is used to create a table for Iterate the related list (nested query) of custom object on lightning component
crossMethodCmpController.js JavaScript Controller File It is hold Javascript Init function to get the data from inner (Nested) soql query in lightning component.
crossMethodCmpHelper.js JavaScript Helper File It is hold Javascript Helper Function to get multiple apex method from lightning controller.
crossMethodCtrl.apxc Apex Class Controller It is used to fetch the opportunity record based on record Id.
opportunityItemCtrl.apxc Apex Class Controller It is used to fetch the opportunity and Report_Cards__c sObject record based on opportunity record Id.
constantsCtrl.apxc Apex Class Controller It’s store the diffrent type of string type value for re-reuse to multiple apex method.

Object:- Opportunity

Fields Name:- Name, StageName, CloseDate, Amount

Custom related Object and their fields:-

Object Name:- Report_Cards__c

Fields Name:- Id, Name, Opportunity__c

Final Output

call multiple controller method from lightning component -- w3web.net

 

You can download file directly from github by Click Here.

 
 

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 

Other related post that would you like to learn in Salesforce

  • Find the below steps

Create Lightning Component

Step 1:- Create Lightning Component : crossMethodCmp.cmp

From Developer Console >> File >> New >> Lightning Component

crossMethodCmp.cmp [Lightning Component File]

  1.    <aura:component controller="crossMethodCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
  2. 	<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>      
  3.     <aura:attribute name="oppListItem" type="Opportunity[]"/>  
  4.     <aura:attribute name="oppObj" type="sObject"/>
  5.     <div class="slds">        
  6.         <table class="slds-table slds-table_bordered slds-table_col-bordered  slds-table--header-fixed" style="border:1px #ccc solid;">
  7.             <tr>
  8.                 <th>Name</th>
  9.                 <th>StageName</th>
  10.                 <th>CloseDate</th>
  11.                 <th>Amount</th>
  12.                 <th>ReportName</th>
  13.                 <th>ReportOppty</th>
  14.             </tr>
  15.             <aura:iteration items="{!v.oppListItem}" var="item">
  16.                 <tr>
  17.                     <td>{!item.Name}</td>
  18.                     <td>{!item.StageName}</td>
  19.                     <td>{!item.CloseDate}</td>
  20.                     <td>{!item.Amount}</td>
  21.                   <aura:iteration items="{!item.Report_Cards__r}" var="reportItem">
  22.                       <td>{!reportItem.Name}</td>
  23.                       <td>{!reportItem.Opportunity__c}</td>
  24.                   </aura:iteration>                    
  25.                 </tr>
  26.             </aura:iteration>
  27.         </table>        
  28.        <br/><br/>
  29.    <!--Start RelatedTopics Section-->
  30. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  31.  
  32.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  33.  
  34.             <br/><br/>
  35.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β†’</span> </strong></p>
  36.             <div style="display:block; overflow:hidden;"> 
  37.                 <div style="width: 50%; float:left; display:inline-block">
  38.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  39.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  40.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  41.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  42.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  43.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  44.                     </ul>
  45.             </div>
  46.  
  47.             <div style="width: 50%; float:left; display:inline-block">
  48.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  49.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  50.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  51.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  52.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  53.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  54.                     </ul>
  55.                 </div>
  56.                <div style="clear:both;"></div> 
  57.                <br/>
  58.                 <div class="youtubeIcon">
  59.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  60.                 </div>
  61.     </div>
  62.  
  63. </div>
  64.  
  65.   <!--End RelatedTopics Section-->
  66.  
  67.     </div>
  68. </aura:component>

Create JavaScript Controller

Step 2:- Create Lightning Component : crossMethodCmpController.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller

crossMethodCmpController.js [JavaScript Controller]

  1.    ({
  2. 	doInit:function(component,event,helper){  
  3.        helper.doInitHelper(component);
  4.     },
  5.  
  6. })

Create JavaScript Helper

Step 3:- Create Lightning Component : crossMethodCmpHelper.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper

crossMethodCmpHelper.js [JavaScript Helper File]

  1.    ({
  2. 	doInitHelper : function(component,event,helper) {
  3. 		 var action = component.get("c.getOppDetail");  
  4.         action.setParams({  
  5.             "recId":component.get("v.recordId"),  
  6.         });      
  7.         action.setCallback(this,function(response){  
  8.             var state = response.getState();              
  9.             if(state=='SUCCESS'){  
  10.                 var result = response.getReturnValue();    
  11.                 //alert(' resultAAA ' +  result.Name);
  12.                 //alert('result ' + JSON.stringify(result));
  13.                 component.set("v.oppListItem",result);  
  14.                 component.set("v.oppObj",result);
  15.                 var reportCard = component.get("v.oppObj.Report_Cards__r[0].Name");
  16.                 //alert('reportCard ' + reportCard);
  17.             }  
  18.         });  
  19.         $A.enqueueAction(action);
  20. 	},
  21. })

Create Apex Class Controller

Step 4:- Create Apex Class : crossMethodCtrl.apxc

From Developer Console >> File >> New >> Apex Class

crossMethodCtrl.apxc [Apex Class Controller]

  1.    public class crossMethodCtrl {
  2.  
  3.     @AuraEnabled
  4.     public static Opportunity getOppDetail(String recId){
  5.         final String needsAnalys = 'Needs Analysis';
  6.         Opportunity opp = opportunityItemCtrl.getOpportunityList(recId);
  7.         Opportunity returnOpp;
  8.         system.debug('opp ' + opp);        
  9.         IF(opp.StageName == constantsCtrl.stageNeedsAnalysis){
  10.              returnOpp = opportunityItemCtrl.getNeedsAnalys(recId, opp.StageName);
  11.             system.debug('returnOppAAA ' + returnOpp);
  12.         }
  13.         RETURN returnOpp;
  14.     }
  15.  
  16. }

Create Apex Class Controller

Step 5:- Create Apex Class : opportunityItemCtrl.apxc

From Developer Console >> File >> New >> Apex Class

opportunityItemCtrl.apxc [Apex Class Controller]

  1.    public class opportunityItemCtrl {
  2.  
  3.   public static Opportunity getOpportunityList(String recId){
  4.       SObjectAccessDecision decision = Security.stripInaccessible(
  5.                                        AccessType.READABLE,
  6.                                        [SELECT Id,Name, StageName, CloseDate, Amount FROM Opportunity WHERE Id =: recId]);
  7.       system.debug('extractOpportunity' + extractOpportunity(decision));
  8.       RETURN extractOpportunity(decision);   
  9.    }
  10.  
  11.  
  12.     public static Opportunity getNeedsAnalys(String recId, String stage){
  13.       SObjectAccessDecision decision = Security.stripInaccessible(
  14.                                        AccessType.READABLE,
  15.                                        [SELECT Id,Name, StageName, CloseDate, Amount, (SELECT Id, Name, Opportunity__c FROM Report_Cards__r  ORDER BY createdDate DESC LIMIT 1)
  16.                                         FROM Opportunity WHERE StageName =: stage AND Id =: recId]);
  17.          system.debug('extractOpportunity222' + extractOpportunity(decision));
  18.       RETURN extractOpportunity(decision);   
  19.    }
  20.  
  21.  
  22.     private static Opportunity extractOpportunity(SObjectAccessDecision decision){
  23.         IF(!decision.getRecords().isEmpty()){
  24.             RETURN (Opportunity)decision.getRecords()[0];
  25.         }
  26.         ELSE{           
  27.             RETURN NEW Opportunity();
  28.         }
  29.     }
  30.  
  31.  
  32. }

Create Apex Class Controller

Step 6:- Create Apex Class : constantsCtrl.apxc

From Developer Console >> File >> New >> Apex Class

constantsCtrl.apxc [Apex Class Controller]

  1.    public WITHOUT sharing class constantsCtrl {
  2.    public static final String stageNeedsAnalysis = 'Needs Analysis';
  3.    public static final String stageValueProposition = 'Value Proposition'; 
  4.    public static final String stageNegotiationReview = 'Negotiation/Review'; 
  5.    public static final String amazonS3Manage = 'amazon s3 manage'; 
  6. }

calling multiple apex method -- w3web.net

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

Can we call one method from another method in Apex Salesforce?

Yes

What is virtual class in Apex?

Virtual class are functional classes and can be instantiated or extended without then need of overriding methods.

What is the use of anonymous window in Apex?

The Execute Anonymous Apex tool in the Developer Console runs the Apex code you enter using ExecuteAnonymous and generates a debug log with the results of the execution. Warning If you call a class that contains a testMethod , all DML statements of the test method execute.

What is apex when doing nails?

The apex should be the highest part of an enhancement, located at the weakest point and created to give the nail balance and strength. It should be visible from every angle but is most noticeable from the side view. The position of the apex varies in different shapes and lengths.

Related Topics | You May Also Like

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

Our Free Courses β†’

πŸ‘‰ Get Free Course β†’

πŸ“Œ Salesforce Administrators

πŸ“Œ Salesforce Lightning Flow Builder

πŸ“Œ Salesforce Record Trigger Flow Builder

πŸ‘‰ Get Free Course β†’

πŸ“Œ Aura Lightning Framework

πŸ“Œ Lightning Web Component (LWC)

πŸ“Œ Rest APIs Integration



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment