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
PRASHANT BHARTIPRASHANT BHARTI 

Update one field of lead object from a custom object B

I am having two object one is Lead and other is custom object Consultant.
In lead there are two field one is area and other is contact_consultant phone number. In Consultant object already contact number is saved according to area. 
My scenario is once a lead is created then it should automatically match area with custom object and populate the contact _consultant phone number.
SEKAR RAJ.SEKAR RAJ.
Hi Prashant,
Try the below logic and change the code as per your requirement.
Trigger LeadTrigger On Lead(After Insert){
       Map<String,Consultant__c> consVsLeadArea = Map<String,Consultant__c>();
      List<Lead> updateLeads = new List<Lead>();
       for(Consultant__c c:[SELECT id,Area,Phone FROM Consultant]){
                consVsLeadArea.put(c.Area,c);
          }
      for(Lead ls:Trigger.New){
           Lead leadToBeUpdated = new Lead(Id=ls.Id);
            leadToBeUpdated.contact_consultant = consVsLeadArea.get(Lead.Area);
            updateLeads.add(leadToBeUpdated);
      }
    if(updateLeads.size()>0){
      update updateLeads;
    }
}

Thanks,
SEKAR RAJ