Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. trigger ContatctoAccount on Contact (before insert, before update) {
  2.  
  3. list<Contact> Cont = new list<Contact>();
  4. Map<String,Account> mapCodeWithAccount = new Map<String,Account>();
  5. for(Account acc: [select id,Account_Code__c from Account where Account_Code__c != Null]){
  6. if(acc.Account_Code__c!= null){
  7. mapCodeWithAccount.put(acc.Account_Code__c, acc);
  8. }
  9. }
  10. for(Contact C : trigger.new){
  11. if(mapCodeWithAccount.containsKey(c.Account_Code__c)){
  12. c.AccountID = mapCodeWithAccount.get(c.Account_Code__c).id;
  13. Cont.add(c);
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement