+ Start a Discussion
wt35wt35 

Trigger.new on before Triggers: need clarification

hello,

 

I am confused with what values the Trigger.new should contain during a trigger on before Update or before Insert.

 

I have a trigger on Case object:

 

trigger limitHighPriorityCases on Case (before insert,before update) {
 
  for (Case c : Trigger.new)
   {
    if ( (c.Priority == 'High') && (c.IsClosed == FALSE) )
    {
      //some code
} } }

 

 

When I update a case with Closed status, the IF loop is executed, which I don't really understand since Trigger.new is supposed to conatin the new version of the case, therefore IsClosed should be equal to TRUE and the IF loop souldn't execute.

 

Could someone clarify?

 

Thank you

Marc

Best Answer chosen by Admin (Salesforce Developers) 
mngmng

It seems the IsClosed standard field is only being set by an internal workflow of some sort, since the value is properly updated during the After trigger.

 

So if you need to update the Case, you're unfortunately going to have to check based on the actual value. However, if you are updating other objects, using an after trigger would help....

All Answers

mngmng

It seems the IsClosed standard field is only being set by an internal workflow of some sort, since the value is properly updated during the After trigger.

 

So if you need to update the Case, you're unfortunately going to have to check based on the actual value. However, if you are updating other objects, using an after trigger would help....

This was selected as the best answer
wt35wt35

You're right. I checked on the picklist value of the Status field and it works great now.

 

trigger limitHighPriorityCases on Case (before insert,before update) {
 
  for (Case c : Trigger.new)
   {
    if ( (c.Priority == 'High') && (c.Status != 'Closed') )
    {
     //some code
    }
   }

}