You need to sign in to do that
Don't have an account?

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.
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.
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