Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger PrimaryContact on Contact (before insert, before update) { set<id> getid = new set<id>(); string contactId; List<Contact> conList = new List<Contact>(); // Trigger Functionality if(Trigger.isInsert || Trigger.isUpdate) { for(Contact cont: Trigger.New) { if(cont.Primary_Contact__c == true) { getid.add(cont.AccountId); contactId = cont.id; } } } // Fetching the other Contact which has primary contact checked List<contact> cList = [select id, Primary_Contact__c from contact where accountid IN: getid AND Primary_Contact__c = true]; // Unchecking the already checked primary contact if(cList.size() > 0) { for(Contact newClst: cList) { if(newClst.id != contactId) { newClst.Primary_Contact__c = false; conList .add(newClst); } } } update conList; }
As mentioned in another question can you try the below code once and respond if there are any issues:
Regards,
Anutej
I used this code, it works fine,
please provide code for above scenerio.
Thanks.
trigger contriacc on Contact (before insert) {
if(trigger.isbefore && trigger.isinsert)
{
set<id> accid = new set<id>();
map<id,string> conmap= new map<id,string>();
for(Contact c: trigger.new)
{
accid.add(c.AccountId);
conmap.put(c.AccountId,c.Name);
}
If (accid.size ()> 0) {
List <Account> upAccList = new List <Account> ();
For (Account ac:
[SELECT Id, ContactsList__c FROM Account WHERE id in: accid ]) {
ac.ContactsList__c + =conmap.get(ac.id) ;
upAccList.add (ac);
}
If (upAccList.size ()> 0)
update upAccList;
}
}
}