Best Practices in Apex Programming

Let us try to understand what are the best practices in Apex Programming.

In this episode we will be discussing about best practices that a developer needs to consider when he crafts Apex code.

Often when I do code reviews I see code which is not bulkified, SOQL queries  being used in for Loops, public access specifier being used though it’s not required and etc.

These are not only bad practices but it also make it hard for other developers to add new functionality when the size of the projects grows.

Few of the practices which I tried highlighting are

  1. Bulkify your code
  2. Proper usage of access modifiers
  3. Refactoring the code
  4. Always write code considering the governor limits
  5. Avoid Hardcoding
  6. Avoid Null pointer Exceptions
  7. Avoid SOQL statements in for loops
  8. Avoid Infinite Loops

In case you want to know more about Apex and Visualforce you can check the Web Series I did.