November 2019
Intermediate to advanced
672 pages
13h 39m
English
Where is the record that is being saved?
The Trigger keyword comes in handy as well and gives us access to current record values (and even to old ones):
1. trigger OpportunityTrigger on Opportunity (before insert, before 2. update, before delete, after insert, after update, 3. after delete, after undelete) { 4. 5. //current record (supposing only one opportunity can be saved at once) 6. Opportunity currentOpp = Trigger.new[0]; 7. 8. //treating before and after events separately 9. if(Trigger.isBefore){10. 11. //following logic 0runs in before insert and update12. if(Trigger.isInsert || Trigger.isUpdate){13. 14. //error if opportunity has a negative amount15. if(currentOpp.Amount <= 0){16. //the addError() method is used ...Read now
Unlock full access