Professional Documents
Culture Documents
Technical Skills
Subject
Best Practices
Goal
English
Comments 16 - 17
02 Naming Rules
• Bulkifying Apex code refers to the concept of making sure the code
properly handles more than one record at a time. When a batch of
records initiates Apex, a single instance of that Apex code is
Bulkify your code executed, but it needs to handle all of the records in that given
batch.
• Example on how to bulkify your code
Using Collections, • It is important to use Apex Collections to efficiently query data and
store the data in memory. A combination of using collections and
Streamlining Queries, streamlining SOQL queries can substantially help writing efficient
and Efficient For Loops Apex code and avoid governor limits.
Use @future Methods for • Only use Synchronous Apex callouts or webservices callouts when
necessary. The differences between synchronous and
Asynchronous asynchronous Apex can be found Governors in Apex
transactions • Code#Synchronous_vs_Asynchronous_Apex
• It is key to have test methods that verify that all Apex code is
Writing Test Methods to properly designed to handle larger datasets and that it does not
Verify Large Datasets exceed governor limits
• Testing Examples
• Methods in Apex should not exceed 100 lines. For large logic
Limit the size of your methods use multiple methods (or helper methods). Apex classes
classes and methods should not exceed 1000 lines. For large logic classes, use multiple
classes (or helper classes)
Use comments in your • Your code should be well commented for others to easily
code understand the logic you worked on
Example:
Documentation: for standard class definitions the following is an example header that might be used:
/**
* @company name
* @author
* @date
* @description
*/
Documentation: for custom controllers and extensions the following header should be used:
/**
* @author Author Name
* @date 3/14/2016
* @description A list of Visualforce pages that use the controller/extension
*/
2. Use indentation to format your code and Visualforce tags in order to facilitate the code readability
3. Avoid using static values in Visualforce pages code. Use custom labels instead
4. Avoid putting JS or CSS code in the Visualforce code. Upload the .js or .css files as Static Resources
instead
5. Avoid using an HTML ID in your Visualforce code. Use the variable $Component to access server
generated IDs
6. Use Visualforce components for complicated Visualforce Pages. Avoid having too many lines in one
Visualforce page
7. Use URLFOR function to reference action, s-control, Visualforce page, or a file in a static resource
archive in a Visualforce page
1. Think about Reusability. Your Lightning component should be, whenever it’s possible, reusable
on other projects by other developers. Avoid referencing project related fields or variable in
your Lightning Component. Make sure your input parameters are dynamic ‘attributes’ and not
‘static’ values.
2. Before making a call to the server, make sure there’s no other option to obtain the data
3. Use attributes, events, or methods to pass data between rather than retrieving the same data in
different components
4. When making a call to the server, limit the columns and rows of the result set:
• Only SELECT the columns you need.
• Set a LIMIT on the query and provide a paging mechanism if needed. Don’t return huge
numbers of rows at once.
6. To enable/disable debug mode: Setup > Custom Code > Lightning Components
7. To enable/disable component caching: Setup > Security > Session Settings > Caching, and
uncheck Enable secure and persistent browser caching to improve performance
8. Upload your .js or .css libraries as Static Resources and reference them in your Lightning
Components. Static resources in Lightning Components.
9. Use multiple inner Lightning Components for complex Lightning Components. Always make
sure that your component is readable and understandable.
02 Naming Rules
VF Page
Wizard VF Page VFP<xy>_<ProcessName><StepNumber> VFP02_ProductLineCreate01
Other VF Page VFP<xy>_<PageName> VFP01_OpportunityMassEdit
Principal:
•Do not use them to hold text that will break if translated to other languages.
Naming convention:
It is best to name custom labels in UPPER_SNAKE_CASE (full capital letters, with “_” between words).
Some rules are to be respected:
On every creation (object, field, record type, process builder, flow, or any declarative option,
except custom labels) we use an Upper Camel Case format for the API name:
• Remove the _ between words.
• Use only English in the naming (labels) Unless otherwise precised by the client
• In case you did use french labels, do not forget to replace the underscores by corresponding
letters. (Passé => Pass___c => Passe__c)
02 Naming Rules
//Action methods
//Logical methods
<access> <return> <name>() { • The method name must follow the camelCase
code_block naming convention in which the first letter is lower
}
case and the first letter of each word in a compound
<access> <return> <name>(param1, param2) { word is capitalized
code_block Ex: startsWithLowerCase
}
• The use of underscore is not allowed.
public String Property { get ; set }
• It is not recommended to use abbreviations.
while (condition) {
code_block Do not remove the curly braces
}
if (condition) {
code_block
}
if (condition) {
code_block
} else {
code_block
}
if (condition) {
code_block
} else if (condition) {
code_block
} else {
code_block
}
Update API Versions • When modifying a class, do not hesitate to update the API Versions
01 Each trigger must be implemented in a custom setting that allows the trigger to be
active/inactive from UI
02 Lorem
Public Ipsum ITriggerHandler{
interface
void beforeInsert();
void afterInsert();
void beforeUpdate();
03
void afterUpdate();
void beforeDelete();
Lorem
void Ipsum
afterDelete();
void afterUnDelete();
Boolean isDisabled();
}
04 Lorem Ipsum
02 Lorem Ipsum
03 Lorem Ipsum
This is a part of the dispatcher code
You can check the complete code from the link below:
https://github.com/kevinohara80/sfdc-trigger-framework
04 Lorem Ipsum
05 Create the SObject Trigger Handler extending the Trigger Handler and implementing the Trigger
Handler Interface
public class SObjectNameTriggerHandler extends TriggerHandler implements ITriggerHandler{
public SObjectNameTriggerHandler(){
Lorem Ipsum
this.newMap
this.oldMap
= (Map<Id, SObject>) Trigger.newMap;
= (Map<Id, SObject>) Trigger.oldMap;
this.triggerNew= (List<SObject>) Trigger.New;
this.triggerOld= (List<SObject>) Trigger.Old;
}
public static Boolean TriggerDisabled = false;
public Boolean isDisabled(){
return TriggerDisabled;
}
Lorempublic
Ipsumoverride void beforeInsert() {}
public override void afterInsert() {}
public override void beforeUpdate() {}
/*
@Author : TMA JMS
@CreatedDate : 11-02-2021
@Description : SObjectName Trigger.
*/
trigger SObjectNameTrigger on SObject(before insert, after insert, before update, after update, before delete, after
delete, after unDelete) {
new SObjectNameTriggerHandler().run();
}
07
• These classes must group generic methods that can be used for
diverse functionalities, for example: a method that verifies if a
Nature given date is before or after the current date, string manipulations,
getting the type of connected user, etc…