function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
himanshu huske 7himanshu huske 7 

Please provide trigger code

update 1 parent 'contact info' text field with names of all the child contact related records names.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Himanshu, 

As mentioned in another question can you try the below code once and respond if there are any issues:
 
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;
  }

Regards,
Anutej
himanshu huske 7himanshu huske 7
Hi Anutej,
I used this code, it works fine,
please provide code for above scenerio.
ANUTEJANUTEJ (Salesforce Developers) 
Sorry Himanshu, I thought it was the same question I think we can do the above with a simple flow I will just check and update the thread.
Thanks.
ANUTEJANUTEJ (Salesforce Developers) 
Can you try this Himanshu once:

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; 
    } 
    }

}