Apex 10 Commandments

Francis Pindar, NetStronghold (UK)
@radnip

Kevin Poorman, Madrona Solutions Group
@codefriar
#1 Thou shalt not put queries in for loops
#1 Thou shalt not put queries in for loops
#2 Thou shalt not put DML in for loops
#2 Thou shalt not put DML in for loops
#3 Thou shalt have a happy balance
between clicks & code
▪ Triggers that replicate declarative functionality.
• Roll-up su...
#4 Thou shalt only put one trigger per object
#5 Thou shalt not put code in triggers other than
calling methods and managing execution order
#6 Thou shalt utilize maps for queries wherever
possible
#7 Thou shalt make use of relationships to reduce
queries wherever possible
#8 Thou shalt aim for 100% test coverage
In general test your methods for:
▪ Positive effects.
• Given proper input it sho...
#9 Thou shalt write meaningful and useful tests
It’s not a test without assertions.
▪ Assert(A==B, “Reason for Assert fail...
#9 Thou shalt write meaningful and useful tests
Test with your own data
▪ Use Test.StartTest() / Test.StopTest()
#9 Thou shalt write meaningful and useful tests
Test one thing at a time
▪ Maintain Focus
▪ Just One Thing!
#10 Thou shalt limit future calls and use
asynchronous code where possible
In general bias towards batch apex
▪ Ensure it ...
Francis Pindar

Kevin Poorman

Technical Consultant
@radnip

Sr. Consultant
@codefriar
The Apex Ten Commandments
The Apex Ten Commandments
The Apex Ten Commandments
The Apex Ten Commandments
The Apex Ten Commandments
The Apex Ten Commandments
Upcoming SlideShare
Loading in...5
×

The Apex Ten Commandments

667

Published on

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.

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
667
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
41
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "The Apex Ten Commandments"

  1. 1. Apex 10 Commandments Francis Pindar, NetStronghold (UK) @radnip Kevin Poorman, Madrona Solutions Group @codefriar
  2. 2. #1 Thou shalt not put queries in for loops
  3. 3. #1 Thou shalt not put queries in for loops
  4. 4. #2 Thou shalt not put DML in for loops
  5. 5. #2 Thou shalt not put DML in for loops
  6. 6. #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
  7. 7. #4 Thou shalt only put one trigger per object
  8. 8. #5 Thou shalt not put code in triggers other than calling methods and managing execution order
  9. 9. #6 Thou shalt utilize maps for queries wherever possible
  10. 10. #7 Thou shalt make use of relationships to reduce queries wherever possible
  11. 11. #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.
  12. 12. #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”)
  13. 13. #9 Thou shalt write meaningful and useful tests Test with your own data ▪ Use Test.StartTest() / Test.StopTest()
  14. 14. #9 Thou shalt write meaningful and useful tests Test one thing at a time ▪ Maintain Focus ▪ Just One Thing!
  15. 15. #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!)
  16. 16. Francis Pindar Kevin Poorman Technical Consultant @radnip Sr. Consultant @codefriar
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×