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 CommandmentsAnd here is a quick recap of what’s mentioned in the article.
Keep the code simple
Don’t put queries in loops
Utilize Map for queries
Use relationships to reduce queries
Don’t put DML in loops
Create only one trigger per object
Keep logic outside of the trigger
Prefer clicks over code wherever possible
Aim for 100% code coverage
Write meaningful tests with asserts
Write unit tests before developing (i.e., test-driven development)
Test all conditions
Don’t use dummy code coverage
Never test with existing data
Don’t introduce extra logic for tests