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
-
Fetch Records
QueriesSecure Email Messagerecords 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
-
Key logic
-
Loops through
Secure_EmailMessage__crecords 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.
-
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