Show Menu

Salesforce Dev Standards Cheat Sheet by

This cheat sheet is for Salesforce programming best practices.

Fields & Object

Object - Without underscore (_) like - Produc­tFe­atu­re__c​
Fields - without underscore (_) like - IsVisi­ble__c
Fields - in Master­-detail or lookup relati­onship append "­Ref­" - Accoun­tRef__c
Fields - in roll-up summary field append "­RS" - Number­OfC­ont­act­sRS__c
Fields - in formula fields append "­F" - Active­Sta­tusF__c


Name should be enough descri­ptive and tell its purpose and type of flow - Produc­tSe­lec­tio­nSc­reenFL
Scheduled flow - SendBi­rth­day­Ema­ils­BatchFL
Record triggers process one record at a time, name should be - Accoun­tCr­eateFL, Accoun­tUp­dateFL
Auto Launch flow - Opport­uni­tyS­ync­Aut­ola­unchFL
Platform event flow - Paymen­tRe­cei­ved­EventFL

Lightning web components

Name should be descri­ptive and follow camelCase, eg: produc­tSe­lec­tio­nTa­ble.html, activi­tyT­ime­lin­e​.html
Variables should also follow camelCase. eg: leadSt­atus, caseOrigin
Java script and css file should also follow camelCase. eg: produc­tSe­lec­tio­nTa­ble.js, activi­tyT­ime­lin­e​.js, produc­tSe­lec­tio­nTa­ble.css, activi­tyT­ime­lin­e​.css

Custom Metadata

Add descri­ption and define its purpose of use.
Use Custom Metadata and apply checks in trigger, flow etc to activate and deactivate any automation

Variables and Methods

Method name should be verb and in camelCase eg: getAco­unt­sBy­Name, applyD­iscount
Apex test method name eg: unitTe­st_­get­Aco­unt­sByName
Variables - local instance and class variables should follow camelCase. eg: isErro­rLo­ggi­ngE­nabled
Constants should be written in UPPER CASE and words separated by unders­cor­e(_). eg: MAXIMU­M_P­ART­ICI­PANTS

Apex Test Execution

Do not use @SeeData = true in test classes
Always write asserts and cover positive and negative scenarios.
Test single and bulk record­s(200)
Try to cover 100% code coverage including exception scenarios as well.
Use mock class for callout scenarios.

Custom Labels

Constants should be defined in CAPS letters for ex: INVALI­D_E­MAI­L_E­RRO­R_M­ESSAGE

Apex & Trigger

Class name should be Descri­ptive Noun or Noun Phrase using PascalCase
Controller - NewAcc­oun­tWi­zar­dCtrl
Extension - NewAcc­oun­tWi­zar­dCt­rlExt
Domain - Account Domain (object specific logic)
Trigger - Accoun­tTr­igger (Object specific triggers)
Trigger Handler - Accoun­tTr­igg­erH­andler (Object specific trigger handler)
Service - Accoun­tSe­rvice (Funct­ion­ality specific service)
Batch - Accoun­tAr­chi­veBatch
Schedule - Accoun­tAr­chi­veS­che­duler
Custom REST - Accoun­tRe­stR­esource
SOAP Resource - Accoun­tSO­APR­esource
Selector - Accoun­tSe­lector (Object Specific Query class)
Test class - Main Class name + "­Tes­t", Accoun­tSe­rvi­ceTest

Lightning Components (Aura)

Descri­ptive name using Pascal­Case​. eg: Produc­tSe­lec­tio­nTable, Activi­tyT­ime­line​
Js file, helper, Event and Applic­ation name should also use Pascal­Case. eg: Config­ure­Quo­teApp, Produc­tSe­lec­tio­nEvent
Variable name should be in camelCase. eg: recordId, contac­tName, isModa­lOpen,

Version control and VS Code

Always use VS Code to commit code in repository
Keep branch name short and descri­ptive. eg: featur­e/J­IRA­-TI­CKE­T-ID.
Commits- message should define the functi­onality and only commit your changes in branch.
Install VS Code extension like Salesforce CLI, SFDX and Salesforce extension pack

Apex Structure and readab­ility

Max 100 characters in single line
max 1000 lines per apex class
max 4 input parameters per method
remove unwanted space and white spaces
Every class must have its test class
Tab width should be 4 white spaces long
Remove all debug statements after completing the functi­onality
Always include curly braces { } to indicate the start and end of looping and branching constructs
keep method definition short up-to 80 lines
Use Contro­ller, Service, Domain, Selector pattern to implement Separation of concer­n(SOC).
Use Javadoc style of code commenting


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Oracle APEX 5 Keyboard Shortcuts Keyboard Shortcuts