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
RahulRahul 

hello friends, I need to update the owner of the lead for a duplicate lead record, if Email address or mobile number matches the previous record, then owner of the second duplicate lead should be automatically the previous owner

Will it be achieved through Trigger, Need help

Thanks in Advance
RahulRahul
In this code it updates owner by the Picklist values(that means if you slect the user from the oicklist values and then you save owner will be updated as selected value) I have the same requirement as updating just the difference is it should update the owner from the first record into the duplicate record. I dont know how to achive this

trigger UpdateOwnerID on Lead(before insert, before update) {
     Set<string> aliasscope = new Set<String>();
      for(Lead opp : trigger.new)
      {
              aliasscope.add(opp.Assigned_To__c);
       }
    map<string,id> userIdbyAlias = new map<string,id>();  //Keep in mind this will only store one user id per alias
    for(User u : [Select id,Name from user where Name IN :aliasscope])
    {
            userIdbyAlias.put(u.Name,u.Id);
     }
    for (Lead objOpportunity : Trigger.new)
    {
       

             if (objOpportunity.OwnerId <> userIdByAlias.get(objOpportunity.Assigned_To__c) )           
             {
                   objOpportunity.OwnerId = userIdByAlias.get(objOpportunity.Assigned_To__c);
              }
         
    }

}