You need to sign in to do that
Don't have an account?
SFDC Guest
Trigger to update previous contact as non primary if new contact is primary.
Hi All,
My requirement is update previous contact as non primary if new contact is primary..
Can you please help me what to write in below trigger. Thanks in advance.
My requirement is update previous contact as non primary if new contact is primary..
Can you please help me what to write in below trigger. Thanks in advance.
Trigger updatePrimaryCheckbox2 on Contact(after insert, after update) { Map < Id, Contact > accConMap = new Map < Id, Contact > (); List < Contact > conList = new List < Contact > (); if (Trigger.isInsert || Trigger.isUpdate) { for (Contact cont: Trigger.New) { if (cont.AccountId != null && cont.IsPrimaryContact__c == true) { accConMap.put(cont.AccountId, cont); } } } for (Contact con: [select id, AccountId, IsPrimaryContact__c, Description from contact where accountid IN: accConMap.keyset() ]) { if (con != null && accConMap.containsKey(con.AccountId)) { // here logic // logic conList.add(con); } } update conList; }
However, I suggest to have seperate handler class and trigger pattern like below:
All Answers
However, I suggest to have seperate handler class and trigger pattern like below: