1

According to Mass Email Limits documentation:

You can send an unlimited amount of email to your org’s internal users, which includes portal users.

However, when you go into Setup--> Mass Email Users and try to build a list view, it will throw an error if the list shows more than 500 users.

This makes it effectively impossible to email all internal users... is there a way around this?

2

There's limits on how many mass emails you can send in a single transaction. You'll necessarily need to build multiple list views and then send them in batches. Alternatively, you could write a batch apex class to email users in batches.

1
  • OK thanks, was hoping they'd have a point-n-click workaround for internal notifications. – smohyee Sep 20 '16 at 16:23
1

If anyone else decides its worth it to them to build a batch apex process for this, here is my template:

//This batch apex class will bypass the 500 recipient limit for emails. Note this does not mean it will bypass the overall daily email limits enforced by SF. 
//This is mainly intended for mass messaging internal and portal users, since SF doesn't have limits on emailing users. 

//MassEmailHandler takes 3 inputs: the ID of the email template you wish to send, a string which refers to a prebuilt SOQL query that returns a list of recipients, and a third optional string to directly input the recipient SOQL query in the case 
//where the entered listName is 'Custom Query'

//Examples: 
// Database.executeBatch(new MassEmailHandler({templateID}, 'Test', '')) will email the recipients returned by the 'Test' query. Note that the third parameter is still required even though it isn't used.
// Database.executeBatch(new MassEmailHandler({templateID}, 'Custom Query', 'SELECT ID FROM User WHERE IsActive=true')) demonstrates how to use the third parameter to manually input a Query.


global class MassEmailHandler implements Database.Batchable<sObject>{

   global final ID templateID;
   global final String listName;
   global final string query;

   global MassEmailHandler(ID templateID, string listName, string customquery){

       this.templateID = templateID;
       this.listName = listName;

       //Build your regularly used queries here, and associate them with a listName 

       if(listName == 'Customer Community Users') query = 'SELECT id FROM User WHERE IsActive = True AND UserType = \'PowerCustomerSuccess\'';
       if(listName == 'Test') query = 'SELECT ID FROM User WHERE LastName = \'Mohyee\'';
       if(listName == 'Custom Query') query = customquery;


   }

    global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope){

        list<ID> recipientIDs = new list<ID>();

        for(sObject obj : scope) recipientIDs.add(obj.ID);

        Messaging.MassEmailMessage mail;

        if(listName == 'Customer Community Users') mail = portalMessage();
        else if(listName == 'Test') mail = testMessage();
        else mail = new Messaging.MassEmailMessage();

        mail.setTemplateID(templateID);
        mail.setTargetObjectIDs(recipientIDs);
        mail.saveAsActivity=false;

        list<Messaging.SendEmailResult> serList = Messaging.sendEmail(new Messaging.MassEmailMessage[]{mail});



    }

    global void finish(Database.BatchableContext BC){

    }

    public Messaging.MassEmailMessage portalMessage(){
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setSenderDisplayName('Verscend Client Portal Admin');
        mail.setDescription('Client Portal Mass Email');

        return mail;
    }

    public Messaging.MassEmailMessage testMessage(){
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setSenderDisplayName('Verscend Client Portal Admin');
        mail.setDescription('Test Email');

        return mail;
    }

}

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.