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
CBBsfdcCBBsfdc 

Write a trigger to update owner of the Case record to current user when status is updated to working

Best Answer chosen by CBBsfdc
Deepali KulshresthaDeepali Kulshrestha
Hi,

Please try this code:

trigger CaseUpdate on Case (before update) {
    
    for(Case c:trigger.New){
      if( Trigger.oldMap.get( c.id ).Status != Trigger.newMap.get(c.id ).Status && Trigger.newMap.get(c.id ).Status =='Working')   
            c.OwnerId=Userinfo.getUserID();
  }

}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi,

Please try this code:

trigger CaseUpdate on Case (before update) {
    
    for(Case c:trigger.New){
      if( Trigger.oldMap.get( c.id ).Status != Trigger.newMap.get(c.id ).Status && Trigger.newMap.get(c.id ).Status =='Working')   
            c.OwnerId=Userinfo.getUserID();
  }

}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
This was selected as the best answer
Raju yadavRaju yadav
Hi CBB123456,
trigger updateCaseUserID on Case (before update) {
    
    for(Case thisCase:trigger.New){
      if( Trigger.oldMap.get( thisCase.id ).Status != Trigger.newMap.get(thisCase.id ).Status){
 
         if(Trigger.newMap.get(thisCase.id ).Status =='Working')) {  
           thisCase.OwnerId=Userinfo.getUserID();
          }
     }
  }
}

Thanks,