0

In Salesforce Lightning, We use @AuraEnabled annotation for method in server side apex controller.All the @AuraEnabled Methods are static. But Static methods loads in memory first and could take lot of heap space.Whats the reason that Salesforce has kept these methods as static. because having lot of static methods will take more heap space. Any special reason behind this.

1
  • Static methods don't use heap space. Maybe you're confusing static methods with static variables?
    – sfdcfox
    Commented May 3, 2019 at 13:10

1 Answer 1

6

@AuraEnabled methods are static for the same reason that Visualforce remoting methods are static: because those architectures don't maintain any state on the server. State would be represented as an object instance to which a member function is bound.

In both paradigms - Aura and Visualforce remoting -, state is kept on the client in JavaScript. Since static functions also don't maintain state outside of the bounds of a transaction since they aren't bound to an object instance, they are the required Apex structure for making such server calls.

But Static methods loads in memory first and could take lot of heap space

having lot of static methods will take more heap space

I'm not sure where these assumptions are coming from but I think there's a core misunderstanding of what static methods do. I would be happy to discuss further if you expand on this.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .