• Gireesh A 7
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 7
    Replies
trigger UpdateOwnerID on Case (after insert) {

 

List<Case> cases = new List<Case>();

map<Id,String> userIdbyAlias = new map<Id,String>();  //Keep in mind this will only store one user id per alias
    
    for(User u : [Select id,Name from user where IsActive = true AND Profile.Name = 'AH JP – Customer Request Agent'])
    {
            userIdbyAlias.put(u.Id,u.Name);
            system.debug('*** User names'+userIdbyAlias);
     }
  system.debug('**List of user from profile **'+userIdbyAlias);
   for (Case c : [Select Id, OwnerId, CreatedById From Case Where Id IN : Trigger.newMap.keySet()]) {

     for(User u :userIdbyAlias.keySet()){

     if(u.contains(c.OwnerId)) {

            c.OwnerId = userIdByAlias.get(u).Id;
            cases.add(c);
       }
  
     }
  }
   if(cases.size() > 0)
            update cases;
            system.debug('*** Final Output ***'+cases);
}
trigger UpdateOwnerID on Case (after insert) {

 

List<Case> cases = new List<Case>();

map<Id,String> userIdbyAlias = new map<Id,String>();  //Keep in mind this will only store one user id per alias
    
    for(User u : [Select id,Name from user where IsActive = true AND Profile.Name = 'AH JP – Customer Request Agent'])
    {
            userIdbyAlias.put(u.Id,u.Name);
            system.debug('*** User names'+userIdbyAlias);
     }
  system.debug('**List of user from profile **'+userIdbyAlias);
   for (Case c : [Select Id, OwnerId, CreatedById From Case Where Id IN : Trigger.newMap.keySet()]) {

     for(User u :userIdbyAlias.keySet()){

     if(u.contains(c.OwnerId)) {

            c.OwnerId = userIdByAlias.get(u).Id;
            cases.add(c);
       }
  
     }
  }
   if(cases.size() > 0)
            update cases;
            system.debug('*** Final Output ***'+cases);
}