Thursday, 31 March 2016

10 Commandments of Programming

Howdy programmers? Programming in a multi developer ecosystem like is nothing less than a band of musicians playing in an orchestra. Different instruments produce vivid tones, but exist in harmony, churning out a beautiful melody. Similarly, keeping the originality of each developer intact, yet ensuring the code adheres to common basic protocols, is of prime importance. Adding a method to the madness is required here!

After going through multiple articles concerning the best practices around programming, I deduced that although a lot of those struck the right chord, some, however, seemed to lack practicality while writing code.

This led me to the idea of writing of this blog to share an exhaustive checklist that ensures uniformity through basic standards  and is practical to use while programming on

I call them the "Ten Commandments of Development" and here they are....

Thou Shalt...
NOT CODE unless it is really required. Use Workflows, Approval process, Validation Rules, Roll up Summary fields, Formula fields, and Process builder etc. to accomplish the requirement.
Always ensure general coding sanity.
  1. Don’t hard code IDs or String values. Use custom settings, Constants (static final variables) or Custom Labels instead.
  2. Always check for nulls within code. Use String.isBlank() or  list.isEmpty().
  3. Use String.equalsIgnoreCase() instead of equality operators(== or ===).
  4. Use meaningful naming conventions for variable, class, test class, trigger and page names. e.g. (MAX_ATTEMPTS, isActive, commissionControllerTest, AccountTrigger, viewCommissions).
  5. Document your code using class and method level comments.
Not use SOQL statement or DML operation within loops. Always use Lists, Sets, Maps to your code. Use SOQL for loops wherever applicable.
Always use nested or Inner SOQL queries to fetch parents and associated child records Use selective SOQL Queries using appropriate WHERE clause, filters on indexed fields (Name, Id, Unique fields) to fetch appropriate result set optimally.
Ensure creating only one trigger per object Use the Trigger Handler Framework to ensure execution control, Trigger Context Variable, Recursion checks.
Optimize Visualforce page view state for performance. Use transient variables, minified Javascript files, Streaming API, Standard Set controllers, and remove unused variable.
Always ensure error logging and reporting within your code. Use try, catch or email to catch and report errors within your code.
Always enforce security in code. Use with sharing, FLS checks, CRUD checks, Escape URL parameters to ensure authorized access.
Always write unit tests based on test cases. Use Test Data creation framework along with the @isTest, test.startTest() test.stopTest(), System.assertEquals(),bulk test data, different users / Profiles, WebServiceMock, 90% code coverage and check for limit uses.
Always ensure modularity and reusability in code
  1. Refactor method having > 45 lines of code into smaller methods, merger multiple line of code into a single line.
  2. Remove unused variables, System.debug(), alert().

In addition to using these 10 Commandments as a guideline, programmers performing code review can use this as a tool to patrol their implementations.

Happy Coding and “May the force be with you!!”

Written by Parmanand Yadav, Salesforce Champion at Eternus Solutions


  1. thanks for shared wonderful information of giving best information.its more useful and more helpful. great doing keep sharing
    salesforce Training in Chennai