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
keiseikeisei 

Visualforce templates are not currently supported for mass email

I tried to test sending mass emails using following test code

sited form Visualforce Manual.

But failed to have received an error message.

Any suggestion appreciated.

In case of sending a singlemassage test,it was OK.

 

 Error Message:-

       System.EmailException:
       SendEmail failed. First exception on row 0;
       first error: INVALID_ID_FIELD,
       Visualforce templates are not currently supported for mass email.: []

 

 Test Code:-

    User you = [ SELECT Email
             FROM User
             WHERE Id = :UserInfo.getUserId()
             LIMIT 1 ];
    EmailTemplate template = [ SELECT Id
                           FROM EmailTemplate
                           WHERE DeveloperName = 'Test_Template'
                             LIMIT 1 ];
     Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
     mail.templateId = template.Id;
    mail.targetObjectIds = new Id[] { you.Id };
    mail.setSaveAsActivity(false);
     Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });

 

Best Answer chosen by Admin (Salesforce Developers) 
Rasmus MenckeRasmus Mencke

You can not use Visualforce email templates with Mass Emails, they are only available with SingleEmails

All Answers

Rasmus MenckeRasmus Mencke

You can not use Visualforce email templates with Mass Emails, they are only available with SingleEmails

This was selected as the best answer
keiseikeisei

Thanks!

This is described  in the wizard  as creating a mail template.

Ad.baylesAd.bayles

You can bypass this limitation using a custom field + a workflow email alert + dataloader :


On your target object :

  1. create a field , for example, a checkbox 'sendemail__c', default value to unchecked
  2. create a workflow rule : "sendemail__c = true"
  3. create an email alert and select your visualforce template
  4. extract record ids of your recipients via a report or the dataloader
  5. load an update on these records (sendemail = true) with the dataloader : all updated records will receive your visualforce email.

This technique works with merge fields and also allows you to bypass the limit of 500 emails / day / organization

TemurifTemurif

Hey, I am working on same problem. 

 

What did you mean by below?

 

load an update on these records (sendemail = true) with the dataloader : all updated records will receive your visualforce email

 

Thanks,

 

 

Ad.baylesAd.bayles
Hi,

You just need to perform an update on the record you want to send the email to, in order to trigger the workflow rule and thus, senf the email alert attached to it.

You can do it manually one by one, but for a large number of record, the dalaloader will allow you to mass update records by loading a CSV file.
Developer 8830Developer 8830
ad.bayles, 

interesting. do you know if there is a limit with this route? does the update have to be made by the data loader or can i update mass recrods from a trigger and still get the emails to send? thanks for your time...