I am new to Force.com and trying to learn some concepts.

Currently I am using Single Email Message to send my emails, but I need to change that to mass email, but I don't quite understand how to do that.

I have also created a Visualforce email template, which I would like to use, but it doesn't seem to work.

It would be great if someone could help me out.

//email_disease_map contains pairs of email address and disease ID
for (Id id : email_disease_map.keySet())
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] defaultAddresses = new String[] {'id@test.com'};

    List<String> toAddresses = new List <String> (email_disease_map.get(id));

    if (!toAddresses.isEmpty())
        //set addresses for email to be sent
        //set up remaining email
        mail.setSenderDisplayName('Ms Test'); 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


From the doc Visualforce email templates cannot be used for mass email

So - how to get around this?

  1. You will need to use a custom field, Workflow email alerts + field update
  2. In your trigger or VF controller, when the affected record(s) are ready to have their mass email sent, mark custom field is_ready_for_mass_email__c to true
  3. The workflow will execute upon the batch of updated records
  4. The object's fields can be used as merge fields for the VF template
  5. The workflow then uses a field update to set is_ready_for_mass_email__c to true

Of course, the recipient will need to be a field of type Email in your object so the email alert has somewhere to send the message to.

  • Yes, exactly. For clarity, crop is saying that you do a mass flip of that checkbox via excel plugin, dataloader, jitterbit, etc Jul 16 '14 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.