+ Start a Discussion
shaker shaikhshaker shaikh 

trigger little confusion in code with (before Insert,Before Update)

before asking my question ...How are you all ?    here i have written simple trigger which will simply update Description field at a time creating case record or update the record but if user has a case record where he found description is updated at the time of creation case record now he wants to modify it but when he saves he again gets same description which he deleted...?  trigger case_comments_update on Case (before insert,Before update ) {    for (case c: Trigger.new){        If(c.status == 'Working'){            c.Description = 'case is in working and user wants to modify this';        }    } }
sowjanya hegdesowjanya hegde
Hi @shaker,

As i understood from the trigger which you have written, whenver the new case is created and wneh you try to update the case record, It will check the status of the case. If it is 'Working', then automatically case description will be updated by the string 'case is in working and user wants to modify this'. anf if you try to edit this description with some other string,and when you try to save this,then also the string you have written in the trigger (case is in working and user wants to modify this) will be updated, not the string which you have typed while editing.

This is how the trigger which you have written works!
shaker shaikhshaker shaikh
thanks looking into this Sowjanya, you got it correct .
 i think i need to remove befor update event. i will make some change and will see it.