Tuesday, January 8, 2013

Lookup Auto Populate:

Lookup Auto Populate:
This example shows how to populate account name lookup on opportunity which depends on another custom lookup which is furthur connected to account.You can try in different by customizing logic part

trigger AccountLookup on Opportunity (before insert, before update) { List<String> AcctNames = new List<String>();  for (Opportunity a:Trigger.new) { AcctNames.add(a.AccountName__c); } List <Account> AcctList = [Select ID from Account where Name in :AcctNames]; for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.new[i].AccountName__c != null)  { Trigger.new[i].Accountid = AcctList[i].ID; } else { Trigger.new[i].Account = null; } } }


              

No comments:

Post a Comment