function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manisha Patil 96Manisha Patil 96 

​​​​​​​Hi,I m a newbie in SFDC. Need some help with this! Can anyone help with writing a trigger on Case object.

Write a trigger on Case object. If custom field Progress value is 0 then update Status to Not Started.  If Progress is 100 then update Status to Complete if progess is 1 to 99 then update Status to In Progress? Note: Both Progress and Status are picklist values



 
Maharajan CMaharajan C
Hi Manisha,

Please try the below code:
 
trigger CaseTrigger on Case (before insert, before update) {        
    for(case cs : Trigger.new){
        if(cs.Progress__c == '0'){
            cs.Status = 'Not Started';
        }
        else if(cs.Progress__c == '1 to 99'){
             cs.Status = 'In Progress';
        }
        else if(cs.Progress__c == '100'){
             cs.Status = 'Complete';
        }
    }
}

Thanks,
Maharajan.C
CharuDuttCharuDutt
Hii Manisha Patil
Try Below Trigger
trigger testTrigger on Case (before insert, before update) {  
      if(trigger.IsBefore){
          if(trigger.IsInsert || trigger.IsUpdate){
    for(case oCase : Trigger.new){
        if(oCase.Progress__c == '0' || oCase.Progress__c == null){
            oCase.Status = 'Not Started';
        }
        else if(oCase.Progress__c == '1 to 99'){
             oCase.Status = 'In Progress';
        }
        else if(oCase.Progress__c == '100'){
             oCase.Status = 'Completed;
        }
        }
        }
    }
}
Please Mark It As Best Answer If It Helps
Thank You!