As one of the biggest cloud computing platforms, Salesforce has completely changed the way organizations do business by introducing a highly adaptable, customized and easy–to–use platform for end–to–end implementation services, i.e. Force.com. Using Force.com, developers can quickly create and deploy trusted cloud applications that are compact, secure, and accessible without worrying about provisioning hardware or application stacks. Moreover, this platform provides separate tools for defining the data model, the business logic, and the user interface.
JavaScript and Salesforce – Go hand–in–hand!
Whether you’re creating a fully reformed UI, integrating data from various sources, or using frameworks such as AngularJS, Ember, React, or Backbone, there’ll be situations where you might need to make heavy use of JavaScript. If you have been following web development over the past few years, you will undoubtedly have noticed the increase in the popularity of JavaScript frameworks when it comes to building web applications. Today, JavaScript frameworks have successfully found their rightful place in the Salesforce development lifecycle.
Using JavaScript in Visualforce Pages
JavaScript allows Visualforce to become the interface you need. – Joshua Birk
While using JavaScript libraries in your Visualforce pages, you will be allowed to:
- Deliver great user experiences.
- Customize the functionality of your Visualforce pages.
- Pass parameters to the JavaScript, show pop-ups, confirm messages, etc.
- Display Visualforce page validation messages as pop-ups.
- Call controller methods from JavaScript.
- Effectively use remote objects (JS data structures that mirror the SFDC database) and action methods (action functions, action support).
- Create a more responsive experience that’s ideal for mobile pages or any other page where your use case requires maximum efficiency and performance.
The best way to include JavaScript in a VF page is by placing the JS in a static resource and then calling it from there. For example,
<apex:includeScript value=”{!$Resource.MyJavascriptFile}”/>
You can then use the functions defined within that JavaScript file using <script> tags.
Salesforce-JavaScript Integration Methods
Action Methods | JavaScript Remoting | Remote Objects | Salesforce REST API | |
Requires APEX Code | YES | YES | NO | NO |
Requires Visualforce | YES | YES | YES | NO |
Have their own Governor limits | NO | NO | NO | YES |
Major advantages | 1. Calls static or instance methods while maintaining controller state 2. Doesn’t require any coding |
1. Calls static Apex methods quickly and efficiently 2. Supports complex server-side application logic 3. Handles complex object relationships better4. Uses network connections (even) more efficiently |
1. Makes basic CRUD object easily accessible 2. Supports minimal server-side application logic |
Helps create, retrieve, update or delete records, using Salesforce applications that support REST and web services |
Limitations | Submits form data very slowly | 1. Limited to static methods 2. The response of the remote call has a maximum size of 15 MB 3. By default, the response of the remote call must return within 30 seconds, after which the call will time out |
1. Remote Objects is subject to change without providing backward compatibility 2. You can retrieve a maximum of 100 rows in a single request. To display more rows, submit additional requests by using the OFFSET query parameter |
Can’t execute custom Apex from VF |