I would like to send an email to 500 Person Accounts every day. The email contains a personalised list of their appointments for the day.

What is the best approach for achieving this using Salesforce?

closed as off-topic by Sebastian Kessel, battery.cord, highfive, Ratan Paul, Rao Aug 21 '18 at 21:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Sebastian Kessel, battery.cord, highfive, Ratan Paul, Rao
If this question can be reworded to fit the rules in the help center, please edit the question.


You would use a scheduled job to run a batchable job to send out the emails. That would look like this:

public class DailyReminders implements Schedulable, Database.Batchable<Sobject> {
  public void execute(SchedulableContext sc) {
    Database.executeBatch(this, 100);
  public Database.QueryLocator start(Database.BatchableContext context) {
    return Database.getQueryLocator([
      SELECT Id FROM Account WHERE IsPersonAccount = TRUE
  public void execute(Database.BatchableContext context, Account[] scope) {
    Messaging.Email[] emails = new Messaging.Email[0];
    EmailTemplate t = [SELECT Id FROM EmailTemplate WHERE Name = 'some template'];

Depending on how many queries you need, you may need to adjust the batch size (100 is depicted here) to avoid governor limits.

  • How would I populate the table/list of appointments in the email? – Robs Aug 20 '18 at 16:53
  • @Robs I thought you had a Visualforce template that did that? Or have you not gotten that far yet? – sfdcfox Aug 20 '18 at 16:56
  • I haven't got that far, because I am not sure how I would display a different list of appointments in each email without hitting a SOQL govenor limit? – Robs Aug 20 '18 at 17:01
  • @Robs If you're using a template, you do need (at least) one query per person. As I stated, you will need to adjust the batch size to the appropriate value to get the desired output. – sfdcfox Aug 20 '18 at 17:06
  • What other options do I have? i.e. how would it work without a template? – Robs Aug 20 '18 at 17:26

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