• NARESH REDDY 67
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Below lines taken from Salesforce Apex Code Developer's guide:
'if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime
error.This includes both direct and indirect operations. For example, if you update account A, and the before update trigger
of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML
update statement or database method, then you are indirectly updating account A in its before trigger, and you will receive
a runtime error'


But I can update the Contact description in the before update trigger. Below is the code:

trigger triggerAllContextVariableCheck on Contact (before update, after update, before insert, after insert) {
    if(Trigger.isBefore){
     if(Trigger.isUpdate){
         for(Contact c: trigger.new){
             c.Description='Before Update'; 
         }}}
}

What I am missing? Above code is updating the Contact record in it's before trigger but the statement in the book says something else.

Please explain.