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
shra1_devshra1_dev 

How to take emailIds in an Object to a List<String>

Hi,

 

 

I hav an object in that I have emailId field. I want to take all the emailId's in that object to a List<String>.

 

how to do this?

 

please help me.........

 

 

Regards,

 

shra1

Best Answer chosen by Admin (Salesforce Developers) 
kritinkritin

List<string> emailIds=new List<String>();
Contact[] cnts=[Select email from contact where email!=null limit 10];
for(Contact c:cnts){
    if(c.email!=null){
      emailIds.add(string.valueof(c.email));
    }
}

 

system.debug(emailIds);