You need to sign in to do that
Don't have an account?
Primary Contact Validation
Hi Everyone,
I have the current trigger set up on the contact object.
What this Trigger currently does is only allow one contact to be selected as the primary contact. I am quite new to coding so I am a little stuck with what I want to achieve.
What I want to modify this code to do is ensure that you cannot select a contact as a primary contact, if that contact is not active. So only active contacts can be selected as primary. Also, if a primary active contact becomes inactive there should be some immediate actions to allow you to select another contact as Primary.
Also, I would like to have an error message display if a user tries to add more than one Primary Contact.
If anyone could help that would be greatly appreciated
Regards,
Raz
Can you please re-post your code .Its not clear enough to go through.
Rgrds,
Rabi
Currently i dont see anything.Instead of pasting it as a iamge.
Copy & Paste the lines of Code.So that its easy enough to debug in personal org.
Rgrds,
Rabi
IsPrimaryContact & Is Active are two fields of Datatype Checkbox on ContactObject
Is my understandfing correct?
set<id> getid = new set<id>();
string contactId;
List<Contact> conList = new List<Contact>();
if(Trigger.isInsert || Trigger.isUpdate) {
for(Contact cont: Trigger.New) {
if(cont.Primary_Contact__c == true) {
getid.add(cont.AccountId);
contactId = cont.id;
}
}
}
List<contact> cList = [select id, Primary_Contact__c from contact where accountid IN: getid AND Primary_Contact__c = true];
if(cList.size() > 0) {
for(Contact newClst: cList) {
if(newClst.id != contactId) {
newClst.Primary_Contact__c = false;
conList .add(newClst);
}
}
}
update conList;
}