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
Supriyo Ghosh 9Supriyo Ghosh 9 

Ownership change through trigger

Hi,

I am having some lead data uploaded in lead management.All the leads are assigned to separate branch queue.I want when a user logged in and modify one lead that lead must be assinged to that particular logged in user.If possible based on one pick list value.Like Lead_Status__c = "Accept".

Please help.
Best Answer chosen by Supriyo Ghosh 9
David Zhu 🔥David Zhu 🔥
You may use the code snippet below as a reference to implement this.
trigger leadtrigger on Lead (after update)
{
    List<Lead> leads = new list<Lead>();
    for (lead l : trigger.new)
    {
         if (l.Lead_Status__c = 'Accept' && trigger.oldMap.get(l.id).Lead_Status__c != 'Accept') && string.valueOf(c.OwnerId).startsWith('00G'))
        {
             l.owner = UserInfo.getUserId();.  
        }
    }

   if (leads.size() > 0)
   {
        Update Leads;
   }
}




 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Supriyo,

I think you will be able to implement this scenario with the help of a trigger can you try checking if this is possible.

Regards,
Anutej
David Zhu 🔥David Zhu 🔥
You may use the code snippet below as a reference to implement this.
trigger leadtrigger on Lead (after update)
{
    List<Lead> leads = new list<Lead>();
    for (lead l : trigger.new)
    {
         if (l.Lead_Status__c = 'Accept' && trigger.oldMap.get(l.id).Lead_Status__c != 'Accept') && string.valueOf(c.OwnerId).startsWith('00G'))
        {
             l.owner = UserInfo.getUserId();.  
        }
    }

   if (leads.size() > 0)
   {
        Update Leads;
   }
}




 
This was selected as the best answer