Most of the pages in our application have been built using HTML5/CSS/Bootstrap/Javascript Remoting/JQuery/AngularJS. Their controllers have most of the methods with @RemoteAction and other static methods called from remote methods. What are some good practices for such controllers.
1 Answer
Few Best Practices I can remember:
- Avoid calling remote function in
for
loop. - Keep payload size minimum in controller
- Don't use global/public variables in static method or any approach like this. Keep everything in method.
- Sometimes same thing needs to be done again and again for each remoting method in controller. Create a common utility for it.
- Remoting count agains API calls, so this limit should be considered.
- Users can lose their network connection in mid-transaction, or alter the way that your page’s JavaScript executes with Firebug and other tools. Always do server/controller side checks before returning results or perform action.
- Remoting can upsert/insert/update in parallel on same object. Design your method to avoid Record Lock situation.
- Use wrapper classes instead of List/Map to return result. This makes the code readable and manageable to your next dev and yourself.
-
I'm fairly certain that remoting calls do not count against the API limit anymore.– JCDCommented Aug 24, 2015 at 13:33
-
@JCD you may be correct but practically I have seen these calls increasing API count. Lets wait to confirm by other.– AshwaniCommented Aug 24, 2015 at 13:43
-
I have been running some javascript remoting in my sandbox and it does seem to be increasing the api usage count? Do you know if it actually does count or not– DieskimCommented Jan 5, 2021 at 11:40