Guest User

Untitled

a guest
Jul 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. trigger associateWithAccount on Contact (before insert) {
  2. //get Company__c from Contact
  3. //lookup Accounts by Account Name using Company__c
  4. //get AccountID from the result of that lookup
  5. //insert AccountID from Account into AccountID in Contact
  6. Map<String, String> extMap = new Map<String, String>();
  7. Set<String> extIdSet = new Set<String>();
  8. for(Contact c : Trigger.new){
  9. extIdSet.add(c.Company__c);
  10. }
  11. for(Account a : [select Id, Name from Account where Name IN :extIdSet]){
  12. extMap.put(a.Id, a.Name);
  13. }
  14. for(Contact c : Trigger.new){
  15. c.Account = extMap.get(c.Id);
  16. }
  17. }
Add Comment
Please, Sign In to add comment