Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger ContatctoAccount on Contact (before insert, before update) {
- list<Contact> Cont = new list<Contact>();
- Map<String,Account> mapCodeWithAccount = new Map<String,Account>();
- for(Account acc: [select id,Account_Code__c from Account where Account_Code__c != Null]){
- if(acc.Account_Code__c!= null){
- mapCodeWithAccount.put(acc.Account_Code__c, acc);
- }
- }
- for(Contact C : trigger.new){
- if(mapCodeWithAccount.containsKey(c.Account_Code__c)){
- c.AccountID = mapCodeWithAccount.get(c.Account_Code__c).id;
- Cont.add(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement