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
Firas Taamallah 18Firas Taamallah 18 

How to get Contacts name from Accounts pass in parameter?

public static List<String> getContactNames(list <Account> accounts){

//
}



how to achieve this ?
AnkaiahAnkaiah (Salesforce Developers) 
Hi Firas,

try with below code.
 
public static List<String> getContactNames(list <Account> accounts){

List<string> contactnames = new List<string>();

for(Contact con:[Select id,Name from contact where AccountId IN:accounts]){
contactnames.add(con.Name);
}

return contactnames;


}

If this helps, Please mark it as best answer.

Thanks!!
 
Firas Taamallah 18Firas Taamallah 18
@ankaiah , not true .. AccountId IN:accounts