Best practices - Visualforce
Visualforce was designed to provide developers with the ability to match the functionality, behavior, and performance of standard Salesforce pages. If your users experience delays, unexpected behavior, or other issues specifically around Visualforce, there are several actions you can take to not only improve their experience, but to also make for improved coding.
Naming conventions:
For naming a visualforce page based on functionality
<Functionality>
The First letter of a visualforce page should always be capital.
For example: OpportunitySearch
If you are overriding a button in an object then,
Override_<Object>_<new/edit>
For example: OverrideAccountEdit
Apex components:
<Functionality>Component
Example: LeadInformationComponent
Few best practices to increase the performance of the page:
Naming conventions:
For naming a visualforce page based on functionality
<Functionality>
The First letter of a visualforce page should always be capital.
For example: OpportunitySearch
If you are overriding a button in an object then,
Override_<Object>_<new/edit>
For example: OverrideAccountEdit
Apex components:
<Functionality>Component
Example: LeadInformationComponent
Few best practices to increase the performance of the page:
- Do not hardcode picklists in Visualforce pages; include them in the controller instead.
- Javascript and CSS should be included as Static Resources allowing the browser to cache them. Never refer a external URL directly in visualforce, in case if the URL is not secured then Salesforce won't allow them to load in the page.
- Use the minified version of JavaScript and CSS since it considerably takes less load time.
- Reference CSS at the top and JavaScript a the bottom of Visualforce pages as this provides for faster page loads.
- Mark controller variables as "transient" if they are not needed between server calls. This will make your page load faster as it reduces the size of the View State.
- Use <apex:repeat> to iterate over large collections.
- Use the cache attribute with the <apex:page> component to take advantage CDN caching when appropriate.
- Use labels instead of hardcoding the values in the page. This may help in case if the pages needs to work on different languages based on the user locale. With the help of Translation workbench this can achieved.
- Check your browser console to see if any resource has failed to load and resolve it.
- Avoid SOQL queries in your Apex controller getter methods.
Comments
Post a Comment