You need to sign in to do that
Don't have an account?
Vidya H 4
if isPrime field in Contact is checked then whenever the new contact is created isPrime field should check and previous contact's isPrime field should uncheck
for the above scenario i need to write trigger.please help
Can you try the below apex trigger.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Is it related to account's contact. Or totally only one contact should be ISPRIME across the org?
Thanks,
Can you try the below apex trigger.
If this solution helps, Please mark it as best answer.
Thanks,
Please follow below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Trigger YourTriggerName on Contact(before insert, before update){
List<Contact> conList = new List<Contact>();
Set<Id> parentAccIds = new Set<Id>();
String contactId ;
If(trigger.IsInsert || Trigger.IsUpdate){
for (Contact c : trigger.new){
if(c.accountId != null){
if(c.IsPrime__c == true){
parentAccIds.add(c.accountId);
contactId = c.Id;
}
}
}
}
List<Contact> conList2 = [Select id, name, IsPrime__c from Contact where accontId IN: parentAccIds];
if(conList2.size>0){
for(Contact con : conList2){
if (con.Id != contactId){
con.IsPrime__c == false;
conList.add(con);
}
}
}
update conList;
}
Please let me know if you need any other help.
Please mark this as best answer if you find it helpful.