Apex Best Practices Checklist

Here is a great article on 15 commandments for Apex best practices, which I think every developer should create as a checklist when writing code. Do read this, as this can transform you from being just a developer to a good developer.

Apex Best Practices: The 15 Apex Commandments

And here is a quick recap of what’s mentioned in the article.

  1. Keep the code simple

  2. Don’t put queries in loops

  3. Utilize Map for queries

  4. Use relationships to reduce queries

  5. Don’t put DML in loops

  6. Create only one trigger per object

  7. Keep logic outside of the trigger

  8. Prefer clicks over code wherever possible

  9. Aim for 100% code coverage

  10. Write meaningful tests with asserts

  11. Write unit tests before developing (i.e., test-driven development)

  12. Test all conditions

  13. Don’t use dummy code coverage

  14. Never test with existing data

  15. Don’t introduce extra logic for tests