0
 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)

1 Answer 1

2

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.

3
  • im using massmessaging method you have given link for single email messasing method if u have anyother idea about this pls comment
    – user7538
    Commented Apr 1, 2014 at 12:29
  • Instead of taking set<Id> contactEmails = new Set<Id>(),You have to use the Set<String> SetofContactEmails = new Set<String>(),then loop through the setofContactEmails..
    – Vineeth
    Commented Apr 1, 2014 at 13:23
  • why you are suggesting set<string? I think finally need to pass List<ID> as the method's parameter.
    – userRg
    Commented Apr 1, 2014 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .