+ 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,