function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
degmodegmo 

Using Static member inside Lightning Component Controller

Hi,
I have an Apex controller that I am calling from my Aura Component.  I am passing a recordId to an @AuraEnabled static method.  The method calls several other methods.  Instead of passing an object from method to method, is it best practice to declar a static object and use it in all methods.  See example blelow:
 
public class myControllerClass {
public static drive__c currentDrive;

@AuraEnabled
Public Static List<Account> processDrives(String currentDriveId) {
    currentDrive = [SELECT field1, field2, field3 FROM drive__c WHERE Id=:currentDriveId];
    List<Account> myAccount = method1();
    return myAccount;
} 

@AuraEnabled
Public Static List<Account> method1() {
   //use currentDrive object to process logic
   if(currentDrive != null && currentDrive.field1 = 'xyz') {
      //more logic here
      List<Drive__c> myDrive = method2(); 
   }
}

@AuraEnabled
Public Static List<Drive__c> method2() {
  //use currentDrive object to process logic
}

@AuraEnabled
Public Static List<Drive__c> method3() {
  //use currentDrive object to process logic
}

}

 
Best Answer chosen by degmo
AnudeepAnudeep (Salesforce Developers) 
Yes, you can definitely use a static member. A similar question is already discussed in this post, I recommend taking a look

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you