Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger associateWithAccount on Contact (before insert) {
- //get Company__c from Contact
- //lookup Accounts by Account Name using Company__c
- //get AccountID from the result of that lookup
- //insert AccountID from Account into AccountID in Contact
- Map<String, String> extMap = new Map<String, String>();
- Set<String> extIdSet = new Set<String>();
- for(Contact c : Trigger.new){
- extIdSet.add(c.Company__c);
- }
- for(Account a : [select Id, Name from Account where Name IN :extIdSet]){
- extMap.put(a.Id, a.Name);
- }
- for(Contact c : Trigger.new){
- c.Account = extMap.get(c.Id);
- }
- }
Add Comment
Please, Sign In to add comment