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
Dan NapolitanoDan Napolitano 

Create Picklist of Contacts in Specific Account

So I am trying to create a picklist of contact names from a specific account (listing available installers) to be assigned as a specific field selection in other accounts. Over time, of course, installer contacts will be added and removed, but it will always be one specific account hosting the contacts.

I thought I would create an Apex trigger to compile that list, but I'm in a bit over my head. Here's what I have so far:
 
trigger Installers on Contact (after update, after insert) 
    {    
       String names='';
       Integer ok=1;
       Set<id> accIdList =  '001G0000022epuD';
       for(Contact con : Trigger.new)
       {
          if(con.accountid!=null)
           accIdList.add(con.accountid);
       }

       List<Account> accUpdateList = new List<Account>();
       for(Account acc : [Select id, name, Contact_Name__c, (Select Id, name From Contacts) From Account Where Id In : accIdList])
       {
           ok=1;
           for(Contact con : acc.contacts)
           {    

              if(con.name!=null)
              {
               if(ok==1)
               {
                names = con.name;
                ok=0; 
               }

               else
                {
                names = names  + ',' + con.name;
                }

             }

           }
         acc.Contact_Name__c = names;
         accUpdateList.add(acc);
       }    
       update accUpdateList;
}

I'm receiving an error: Illegal assignment from String to Set<Id>. Perhaps somebody can help me over the hump here?

Thanks. 
GauravGargGauravGarg
Hi Don,

Please replace line 5 with below code:
 
Set<id> accIdList =  new Set<ID>();
accIdList.add(001G0000022epuD);
Hope this helps, let me know if you still face some issues in it.

Thanks,
Gaurav
Skype: gaurav62990