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
Phil RossiPhil Rossi 

Simple query to generate an email list

I'm a trying to put together a simple query that will create an email list from a list of about 30 account id's. So, basically looking to select email from contact where account ID = xxx, yyy, zzz 

Thanks!
om gupta(sfdc)om gupta(sfdc)
Set<String> accountIds = new Set<String>();
accountIds.add('xyz');

//add all the 30 account id in set or just query also and store on the set

List<Contact> contacts = [select email from Contact where accountId in : accountIds];
Set<String> emailIds = new Set<String>();
for(Contact c : contacts){
   emailIds .add(c.email);

}

//and user the value in emailids

hope it solved your problem

 
Akhilesh Reddy BaddigamAkhilesh Reddy Baddigam
public class emails{
    public static void getEmails(){
        list<String> emails=new list<String>();
    
          list<contact> contacts=[select id,AccountId,Email from Contact where AccountId in (select id from Account  )];
    
          for(contact c:contacts){
    
           emails.add(c.Email); 
          }
    
           System.debug(emails);

    }
}

If this helps you to achieve your requirement please choose this as best answer.
Thank you.