Date post: | 09-May-2015 |
Category: |
Technology |
Upload: | salesforce-developers |
View: | 574 times |
Download: | 0 times |
Apex 10 Commandments
Francis Pindar, NetStronghold (UK)@radnip
Kevin Poorman, Madrona Solutions Group@codefriar
#3 Thou shalt have a happy balance between clicks & code
▪ Triggers that replicate declarative functionality.• Roll-up summary• Workflows• Email Templates• Global Settings• …
Good Salesforce Architectural Design
#8 Thou shalt aim for 100% test coverageIn 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.
#9 Thou shalt write meaningful and useful testsIt’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”)
#9 Thou shalt write meaningful and useful testsTest with your own data
▪ Use Test.StartTest() / Test.StopTest()
#9 Thou shalt write meaningful and useful testsTest one thing at a time
▪ Maintain Focus▪ Just One Thing!
#10 Thou shalt limit future calls and use asynchronous code where possibleIn 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!)