Salesforce Apex Presentation 2
Salesforce Apex Presentation 2
Salesforce Apex Presentation 2
David Liu
SALESFORCE TECHNICAL ARCHITECT
@dvdkliu sfdc99.com
WARNING:
There will be code. There will be LOTS of code.
Demo: Write a basic Apex trigger
Overview - Line by line explanation
- See our trigger in action
Create 500
100 leads Trigger
leads
in trigger loop!
Demo
insert t;
} }
} }
When to Use “before” vs “after” Triggers
Timeline of a Database Event
PROS PROS
- No need to explicitly save your - System fields now available:
work, the save event is coming • Record ID (insert)
• Created Date (insert)
• Last Modified Date (update)
CONS CONS
- System level fields are not - Need to explicitly save your changes
available, they’re not populated - Potentially create infinite loops
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START
FINISH
START