+ Start a Discussion
sfdclearnsfdclearn 

Updating Case Status based on a formula field.

Hi ,

 

   I have a formula field called opportunity stage in the case object. When this case opportunity stage(which is a formula)  goes to Closed/Won the case status(which is a picklist) should go to Resolved.

  I am trying the following trigger. But it displays error when i save the case record. Please help!

 

   

trigger updatecasestatus1 on case (before insert, before update) {
List<case> casetobeupdated = new List<case>();
for(case c : Trigger.new){
if(c.Opportunity_Stage__c == 'Closed/Won')
{

c.status = 'Resolved';
casetobeupdated.add(c);
}
}

if(casetobeupdated != null && !casetobeupdated.isEmpty())
{
update casetobeupdated;
}
}

 

 

Ker Vin.ax1237Ker Vin.ax1237

It would be easier if you provided the actual error message, you know.

 

Anyway, for this scenario, wouldn't it be more straight forward to use a workflow and field update? I tend to try to reduce actual APEX coding - coding is a last resort