+ Start a Discussion
Raghu Sharma 6Raghu Sharma 6 

Lightning Component when to use javascript controller vs apex controller

In which scenarios should we put the logic in apex controller vs java script controller

For eg: For making salesforce SOQL/DML statements, we can put the logic apex controller. Similarly, where should be put the logic for REST API calls? When should we use apex controller? Whar are the best practices
Best Answer chosen by Raghu Sharma 6
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Raghu,

Create a server-side controller in Apex and use the @AuraEnabled annotation to enable access to the controller method.
Only methods that you have explicitly annotated with @AuraEnabled are exposed. Calling server-side actions aren’t counted against your org’s API limits. However, your server-side controller actions are written in Apex, and as such are subject to all the usual Apex limits. A client-side controller handles events within a component. It’s a JavaScript resource that defines the functions for all of the component’s actions.
A client-side controller is a JavaScript object in object-literal notation containing a map of name-value pairs. Each name corresponds to a client-side action. Its value is the function code associated with the action. Client-side controllers are surrounded by parentheses and curly braces. Separate action handlers with commas (as you would with any JavaScript map). hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
 

All Answers

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Raghu,

Create a server-side controller in Apex and use the @AuraEnabled annotation to enable access to the controller method.
Only methods that you have explicitly annotated with @AuraEnabled are exposed. Calling server-side actions aren’t counted against your org’s API limits. However, your server-side controller actions are written in Apex, and as such are subject to all the usual Apex limits. A client-side controller handles events within a component. It’s a JavaScript resource that defines the functions for all of the component’s actions.
A client-side controller is a JavaScript object in object-literal notation containing a map of name-value pairs. Each name corresponds to a client-side action. Its value is the function code associated with the action. Client-side controllers are surrounded by parentheses and curly braces. Separate action handlers with commas (as you would with any JavaScript map). hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
 
This was selected as the best answer
Raghu Sharma 6Raghu Sharma 6
I was looking more for best practices. But anywayz, this helps. Thanks for your inputs