Salesforce Certified Application Architect

Friday 6 October 2017

Can we access @AuraEnabled variables in @AuraEnabled methods?

Yes, you can access static variables, but there's no point for your specific use case. @AuraEnabled is used to expose custom classes and methods to Lightning. Static variables will be reset between each transaction, just as they are in Visualforce.


public class Payload {
    @AuraEnabled public Integer counter;
}
@AuraEnabled public static Payload someMethod(Payload state) {
    if(...) {
        state.counter++;
    } else {
        state.counter--;
    }
    return state;
}
 
 
doSomething: function(component, event, helper) {
    var action = component.get("c.someMethod");
    action.setParams({ state: component.get("v.state"); });
    action.setCallback(function(result) {
        // Not included, but remember to check isValid/result status
        component.set("v.state", result.getReturnValue());
    });
    $A.enqueueAction(action);
} 

No comments:

Post a Comment

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...