You need to sign in to do that
Don't have an account?
degmo
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:
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 } }
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