Apex 10 commandments df14

25
Apex 10 Commandments James Loghry Technical Architect, EDL Consulting @dancinllama Kevin Poorman Principle Architect, EDL Consulting @CodeFriar

Transcript of Apex 10 commandments df14

Page 1: Apex 10 commandments df14

Apex 10 CommandmentsJames Loghry

Technical Architect, EDL Consulting

@dancinllama

Kevin Poorman

Principle Architect, EDL Consulting

@CodeFriar

Page 2: Apex 10 commandments df14

Place

Customer or

Partner logo in

white area of

slide, centered

James LoghryTechnical Architect

Page 3: Apex 10 commandments df14

Place

Customer or

Partner logo in

white area of

slide, centered

Kevin PoormanPrinciple Architect

Page 4: Apex 10 commandments df14

Use to

introduce a

demo, video,

Q&A, etc. Commandments 1-5Kevin Poorman

Page 5: Apex 10 commandments df14

#1 Thou Shalt keep thy code Stupid Simple. (Kiss)

Page 6: Apex 10 commandments df14

#1 Thou shalt keep thy code Stupid Simple. (Kiss)

Page 7: Apex 10 commandments df14

#2 Thou shalt not put queries in for loops

Page 8: Apex 10 commandments df14

#2 Thou shalt not put queries in for loops

Page 9: Apex 10 commandments df14

#3 Thou shalt not put DML in for loops

Page 10: Apex 10 commandments df14

#3 Thou shalt not put DML in for loops

Page 11: Apex 10 commandments df14

Why bulkification?

Salesforce runs on a multi-

tenant architecture. Hence,

governor limits and bulkification

are needed.

Page 12: Apex 10 commandments df14

#4 Thou shalt only put one trigger per object

Page 13: Apex 10 commandments df14

#5 Thou shalt not put code in triggers other than calling methods and managing execution order

Page 14: Apex 10 commandments df14

Use to

introduce a

demo, video,

Q&A, etc. Commandments 6-10James Loghry

Page 15: Apex 10 commandments df14

#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.

Page 16: Apex 10 commandments df14

#7 Thou shalt utilize maps for queries when needed

Page 17: Apex 10 commandments df14

#8 Thou shalt make use of relationships to reduce queries wherever possible

Page 18: Apex 10 commandments df14

#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.

Page 19: Apex 10 commandments df14

#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.

Page 20: Apex 10 commandments df14
Page 21: Apex 10 commandments df14
Page 22: Apex 10 commandments df14
Page 23: Apex 10 commandments df14

#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!

Page 24: Apex 10 commandments df14

Use to

introduce a

demo, video,

Q&A, etc. Questions & Answers

Page 25: Apex 10 commandments df14