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

Updating Lookup Field
Hi everyone,
I have US university names stored in Accounts. I also collect information from web-to-lead, "university name" is a drop down comes as a text field from web site to lead. Landing field in Leads is called 'University Name". (University_name__c) I would like to update lookup field "University" in Leads (University__c) (which is a lookup and connected to Accounts) by using the text value from University_name__c. Here is the code I am working with. I appreciate a lot if anyone can help.
trigger LeadAccount on Lead (before insert, before update) {
List<String> LeadUni = new List<String>();
//University_name__c is a text field in Leads
for(Lead ld : trigger.new)
if(ld.University_name__c != null)
LeadUni.add(ld.University_name__c);
//AccountMap stores Account id from University_name__c field because Account.Name = Lead.University_name__c.
Map<String, Account> AccountMap = new Map<String, Account>(
[SELECT id from Account where name IN: LeadUni]);
for(Lead ld : Trigger.new)
ld.University__c = AccountMap.get(ld.University_name__c).id;
}
Thanks
Hi Eprasu,
Your solution was great, I appreciate a lot for the response. I made a little change with the last part of the code and it works. I am going to post the correct code and people can use it.
Thanks again.
All Answers
Following is the rough drafted code. I have not tried to execute it. Let me know if you find any issues.
Hi Eprasu,
Your solution was great, I appreciate a lot for the response. I made a little change with the last part of the code and it works. I am going to post the correct code and people can use it.
Thanks again.