Find your content:

Search form

You are here

can we use soql query in set method

 
Share
 List <Account> accountId=[SELECT Id FROM Account WHERE Name = 'Customer'or Name = 'Sales' or Name = 'order' ]; 
 List <Contact> contacts=[SELECT id,Email FROM Contact WHERE AccountId = :accountId ];  
 Set<Id> contactEmails = new set<Id>();
 for(Contact contact: contacts)
 {
 contactEmails.add(contact.Id); 
 } 

Messaging.MassEmailMessage emails = new Messaging.MassEmailMessage();
emails.setTargetObjectIds(contactEmails);  
emails.SaveAsActivity=(false);
Messaging.sendEmail(new Messaging.MassEmailMessage[] { emails });
return null;

Its showing the error:: method does not exist [messeging .mass email ] settargetobject id(set)


Attribution to: user7538

Possible Suggestion/Solution #1

settargetobject(Id) method has Id as a parameter but you are passing set that's why you are getting this error. Here's the [link][1] for setTargetObjectId(ID) method.

Yes you can have more than one Id in case of MassEmail.

But setTargetObjectId(Id[]) method is taking List as a parameter in case of MassEmail instead of Set. So, you can try it like this:

List<Id> conEmails = new List<Id>(contactEmails);

Now you can pass this List<Id> as a parameter as setTargetObjectId(conEmails);

Hope it would help you.


Attribution to: userRg
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31499

My Block Status

My Block Content