You need to sign in to do that
Don't have an account?

can any one say what error in this code
public PageReference send()
{
List<Contact> contacts=[Select Id,Email From Contact Where AccountId='001i000000g7erl'];
List<Id> Conids=new List<string>();
for(Contact mail: contacts)
{
Conids.add(mail.Email);
}
Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage();
emails.setTargetObjectIds(Conids);
emails.setTemplateId('00Xi0000000J9hx');
emails.setsubject('note');
emails.setplainTextBody('body');
Messaging.SendEmail(New Messaging.MassEmailMessage[] {emails});
return null;
}
when im clicking the send button
the error is ::System.StringException: Invalid id: vivekravi@gmail.com
Error is in expression '{!send}' in component <apex:commandButton> in page brand
this the error can any one solve this error for me
{
List<Contact> contacts=[Select Id,Email From Contact Where AccountId='001i000000g7erl'];
List<Id> Conids=new List<string>();
for(Contact mail: contacts)
{
Conids.add(mail.Email);
}
Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage();
emails.setTargetObjectIds(Conids);
emails.setTemplateId('00Xi0000000J9hx');
emails.setsubject('note');
emails.setplainTextBody('body');
Messaging.SendEmail(New Messaging.MassEmailMessage[] {emails});
return null;
}
when im clicking the send button
the error is ::System.StringException: Invalid id: vivekravi@gmail.com
Error is in expression '{!send}' in component <apex:commandButton> in page brand
this the error can any one solve this error for me
public PageReference send()
{
List<Contact> contacts=[Select Id,Email From Contact Where AccountId='001i000000g7erl'];
List<Id> Conids=new List<string>();
for(Contact mail: contacts)
{
Conids.add(mail.Id);
}
Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage();
emails.setTargetObjectIds(Conids);
emails.setTemplateId('00Xi0000000J9hx');
emails.setsubject('note');
emails.setplainTextBody('body');
Messaging.SendEmail(New Messaging.MassEmailMessage[] {emails});
return null;
}
Reference : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_mass.htm
Thank you,
Choose it as best answer, If it resolved your issue.
All Answers
public PageReference send()
{
List<Contact> contacts=[Select Id,Email From Contact Where AccountId='001i000000g7erl'];
List<Id> Conids=new List<string>();
for(Contact mail: contacts)
{
Conids.add(mail.Id);
}
Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage();
emails.setTargetObjectIds(Conids);
emails.setTemplateId('00Xi0000000J9hx');
emails.setsubject('note');
emails.setplainTextBody('body');
Messaging.SendEmail(New Messaging.MassEmailMessage[] {emails});
return null;
}
Reference : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_mass.htm
Thank you,
Choose it as best answer, If it resolved your issue.
Adding Emails to the list is causing exception I feel. Try just addding Id to the list Conids and also change the intialization part of list Conids.
List<Id> Conids=new List<id>();
for(Contact mail: contacts)
{
Conids.add(mail.id);
}
For mass email, no need to mention Subject, tr after removing subject field also.
Let me know if this approach helps you.
---Praveen.