Secure Email

BatchSendSecureEmail: Batch to Send Bulk/Scheduled Secure Emails

The BatchSendSecureEmail job is responsible for sending Secure Emails (via Paubox) that are flagged to be processed through batch mode.


Batch Job: BatchSendSecureEmail

  • Salesforce Batch Apex class designed to query Secure Email messages that needs to be processed via Batch OR are scheduled and current time is on or after the Scheduled Time.


How It Works

  1. Fetch Records
    Queries Secure Email Message records that meet all the following conditions:

  • cmsecureemail__Process_Via_Batch__c = true

  • cmsecureemail__Email_Status__c = 'created'

  • RecordType.DeveloperName = 'Outbound'

  • cmsecureemail__Schedule_Time__c = null OR (cmsecureemail__Schedule_Time__c != null AND cmsecureemail__Schedule_Time__c <=: currentDateTime)

  • It appends a date filter (LAST_N_DAYS) based on CreatedDate

CreatedDate = LAST_N_DAYS:DataTransfer_Settings__c.SecureEmailBatch_LastNDays

Default lookback = 2 days


  1. Key logic

  • Loops through Secure_EmailMessage__c records to send them via API.

  • Calls status API via:

    • InvocableSendSecureEmailService.callSecureEmailService()

  • Email Status is updated to Processing

  • Batch to Pull Secure Email Status will be responsible to update the latest status of the Emails.

BatchPullSecureEmailStatus: Batch to Get Latest Status of Secure Email
  1. Next Scheduling

Schedules the next batch execution:

  • Reads time delay from DataTransfer_Settings__c.NextBatchProcessSecureEmail

  • Automatically schedules ScheduleBatchSendSecureEmail


Automation

  • This batch can be scheduled to run daily to automatically update the status of Secure Email Messages for each day.

ScheduleBatchSendSecureEmail

Execution Script

👉 Run batch without filter (uses metadata-based query):

Database.executeBatch(new BatchSendSecureEmail(), 1); 

👉 Run batch with a custom SOQL query:

String sQuery = <custom query>;
Database.executeBatch(new BatchSendSecureEmail(sQuery), 1); 

Summary

  • Configure Custom Settings (query clause, retry interval).

  • Use the provided BatchSendSecureEmail class.

  • Schedule the batch to run hourly (or per your business requirement).

  • Monitor the batch job to ensure all emails are moved to processing status