0

We have an Apex batch class which processes 2950 records of contacts, sending them emails with Messaging.SingleEmailMessage method(The query has a filter for IsEmailBounced = FALSE AND Email != NULL). We run it divided to chunks of 20/40 contacts, with single usage of Messaging.SendEmail method per transaction(single execute chunk). We get no errors at all in execution but two awkward things are occurring since we added new contacts recently:

  1. Only 2000(exactly) emails are sent although the QueryLocator size if of 2950 contacts.
  2. The Total Batches number is changing while processing batches chunks.
4
  • Have you checked the daily external email sending limits on your org? Sending using email addresses or contact IDs count towards this limit (typically 5000 on a production org).
    – Phil W
    Jun 20, 2023 at 21:48
  • Forgot to mention, but of course not hitting that limit
    – DavidS
    Jun 20, 2023 at 22:02
  • the number 2000 makes me think of SOQL OFFSET clause which is limited to 2000. What does your start() method look like? (Use edit)
    – cropredy
    Jun 20, 2023 at 22:40
  • return Database.getQueryLocator('SELECT ID FROM Contact WHERE HasOptedOutOfEmail = FALSE AND IsEmailBounced = FALSE AND Email != NULL');
    – DavidS
    Jun 20, 2023 at 22:52

1 Answer 1

2

The reason for the failing emails was the error: The maximum number of times this file can be shared has been exceeded Sharing a file with Messaging.SingleEmailMessage.SetEntityAttachments(ContentVersionIds) has the limit of 2000 sharing per file as stated here: https://help.salesforce.com/s/articleView?id=sf.collab_files_size_limits.htm&type=5

File Sharing Limits
A file can be shared a maximum of 2000 times. This count includes shares with records, people, and groups. If a file is approaching the maximum number of shares, consider creating a public link or making the file public by posting it to your feed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .