The ten commandments of Apex are the fundamental rules that good Force.com developers always use when developing. Join us to learn the common pitfalls that often cause difficulties for new developers to the platform so you can architect and develop top-notch Force.com applications.
10. #5 Thou shalt not put code in triggers other than
calling methods and managing execution order
11. #6 Thou shalt utilize maps for queries wherever
possible
12. #7 Thou shalt make use of relationships to reduce
queries wherever possible
13. #8 Thou shalt aim for 100% test coverage
In general test your methods for:
▪ Positive effects.
• Given proper input it should act like this.
• Not just happy path, but all logic branches.
▪ Negative effects.
• Given bad data it should error like this.
▪ Role/Profile/User effects
• Given a user with X profile and Y role it should act like this.
14.
15.
16.
17. #9 Thou shalt write meaningful and useful tests
It’s not a test without assertions.
▪ Assert(A==B, “Reason for Assert failure”)
▪ AssertEquals(A,B, “Reason for Assert failure”)
▪ AssertNotEquals(A,B, “Reason for Assert failure”)
18. #9 Thou shalt write meaningful and useful tests
Test with your own data
▪ Use Test.StartTest() / Test.StopTest()
19. #9 Thou shalt write meaningful and useful tests
Test one thing at a time
▪ Maintain Focus
▪ Just One Thing!
20. #10 Thou shalt limit future calls and use
asynchronous code where possible
In general bias towards batch apex
▪ Ensure it runs as efficiently as possible.
• Limit and tune time outs for callouts.
• Tune soql queries for efficiency – dev console can help here.
▪ If you need @future methods.
• Optimize them the same way you would optimize your batch apex.
• Resist methods that would queue many @future calls at once. (governor limits!)