Apex 10 commandments df14
-
Upload
james-loghry -
Category
Software
-
view
87 -
download
0
Transcript of Apex 10 commandments df14
Apex 10 CommandmentsJames Loghry
Technical Architect, EDL Consulting
@dancinllama
Kevin Poorman
Principle Architect, EDL Consulting
@CodeFriar
Place
Customer or
Partner logo in
white area of
slide, centered
James LoghryTechnical Architect
Place
Customer or
Partner logo in
white area of
slide, centered
Kevin PoormanPrinciple Architect
Use to
introduce a
demo, video,
Q&A, etc. Commandments 1-5Kevin Poorman
#1 Thou Shalt keep thy code Stupid Simple. (Kiss)
#1 Thou shalt keep thy code Stupid Simple. (Kiss)
#2 Thou shalt not put queries in for loops
#2 Thou shalt not put queries in for loops
#3 Thou shalt not put DML in for loops
#3 Thou shalt not put DML in for loops
Why bulkification?
Salesforce runs on a multi-
tenant architecture. Hence,
governor limits and bulkification
are needed.
#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
Use to
introduce a
demo, video,
Q&A, etc. Commandments 6-10James Loghry
#6 Thou shalt have a happy balance between clicks & code
– “I’ve reached the maximum number of workflows”
– Triggers that replicate declarative functionality.
• Roll-up summary
• Workflows
• Flow Triggers
– Using Custom Settings instead of constructing a map in
Apex
– Using formulas instead of duplicating fields
Know which tool
is right for the
job.
#7 Thou shalt utilize maps for queries when needed
#8 Thou shalt make use of relationships to reduce queries wherever possible
#9 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.
Bulkification
• Load 200 or more records to test limits.
#10 Thou shalt write meaningful and useful tests
• Not a test without System.assert calls
• System.assert(A==B,’A does not equal B’)
• System.AssertEquals(A,B)
• System.AssertNotEquals(A,B,’A equals B, but shouldnt’)
• The more assertions the better.
• Create mock data, never rely on existing production data.
• Test all conditions, not just positive test cases
• Test one criteria per unit test.
#Bonus! Thou shalt feel free to break these as wisdom merits.
After all:
Sometimes you just need a list of Id’s
These commandments, despite their
name, are guidelines for success, not
syntactical rules you just can’t break.
Break them if you need to, Adhere if you
can – they’ll save you time in the long run.
Except for
bulkfiying SOQL
and DML!
Use to
introduce a
demo, video,
Q&A, etc. Questions & Answers