top of page
Writer's pictureD. Dewangan

How to Implement Batch Processing in Flows



Ready to transform your business workflows? With Salesforce Batch Management, you can handle large data sets effortlessly! Join me as I walk through creating batch jobs to send weekly case closure notifications and clean up records—all without writing code. From setup to monitoring and managing batch jobs, this guide makes it easy. Let’s explore how to streamline your workflows together and achieve more with fewer clicks!

With Batch Apex, handling large data sets or extended tasks in Salesforce is simplified. This post covers setting up Batch Implementation, structure, best practices, and real-world examples. Batch Management requires no code—just a few clicks in the UI. It allows you to run and monitor multiple batch jobs within a scheduled flow.


Note: Feature is only available in the developer org not in the scratch or sandbox  org

In our scenario, we will send case close notifications for each closed case this week and clean up the closed cases. We would notify the ERM team for each case being closed.

We will approach this whole solution with flows and learn about batch implementation through Salesforce Batch Management.


Here are the steps to achieve the functionality:

  1. Create a custom label.

  2. Create an email template.

  3. Create an auto-launched flow(no trigger).

  4. Create a batch job using Batch Management.

  5. Create a scheduled flow.


Let's start:

Step  1. Create 2 custom labels.

  1. Recipient Address: ERM Email: erm@avenoir.ai

  2. Sender address: No-reply Email: no-reply@avenoir.ai


Step  2. Create an email template.

  1. Name: Case Closed Notification

  2. Developer Name: Case_Close_Notification

  3. Related Entity Type: Case.

  4. Select Folder: Choose the folder location you want to save the template in.

  5. Subject and HTML Value: Set the subject and HTML value as per your need.


Step  3. Create an auto-launched flow(no trigger).

  1. Name: Closed Cases Notification And Cleanup.

  2. Create a variable: recordId (Text and available for input)

  3. Add Decision element: has RecordId

    1. Yes : recordId isNull False

    2. Default Outcome: No

  4. Add Get Records : 

    1. Object: Email Template

    2. Filter Criteria: Developer Name Equals Case_Close_Notification

  5. Add an Email Action : 

    1. Label: Email for closed Cases

    2. Api Name: Email_for_closed_Cases

    3. Email Template ID: get records> Email Template ID

    4. Recipient Address List: custom label: ERM Email

    5. Recipient ID: contactId (Any contact with a valid email address)

    6. Related Record ID: recordId

    7. Sender Email Address: customlabel: No-reply Email

  6. Add Delete Records :

    1. Specify conditions: 

      1. Object: Case

      2. Filter Criteria: Id Equals recordId

  7. Save and activate the flow.


Step  4. Create a batch job using Batch Management.

  1. Go to Setup > Home > Quick Find > Batch Management.

  2. Click on the New button.

  3. Fill in the Details Section :

    1. Name: Case Closed Notifications

    2. Api Name: Case_Closed_Notifications

    3. Process Type: Flow

    4. Execution Process: Closed_Cases_Notification_And_Cleanup

    5. Group: Support

    6. Batch Size: 10 (as we need to send an email for each closed case)

    7. Retry Count : 0

    8. Retry Interval: 1000

    9.  Flow Input Variable: recordId

  4. Click on the Next button.

  5. Fill in the Object  and Criteria section : 

    1. Object: Case

    2. Criteria: Closed Equals Value True

  6. Hit the Save button.

  7. Activate the batch job.


Step  5. Create a scheduled flow.

  1. Name: Send Email For Closed Cases

  2. Api Name: Send_Email_For_Closed_Cases

  3. Start Date: Today 

  4. Start Time: 10:00 AM

  5. Frequency: Weekly

  6. Add Action Element : 

    1. Name: Process Closed Cases

    2. API Name: Process_Closed_Cases

    3. Add: Case_Closed_Notifications 

    4. (Batch job created in above step)

  7. Activate the flow.


Now as all things are in place, the ERM team would be notified for cases closed weekly.

Let us now learn more about the batch implementation:


Monitoring of batch jobs

  1. Go to Setup > Monitor Workflow Services.

  2. View all batch job instances in the list.

  3. Select the batch job instance to view Details and Parameters.

  4. View the Tasks tab for details on batch job parts.

  5. View the Failed Records tab for records the batch job couldn’t process.


Submit Failed Records

If you choose to submit specific failed records for processing, you can select up to 200 failed records. After you resubmit the failed records, their status changes from Failed to Resubmitted. To process the failed records, a new batch job is created and run automatically.


  1. To submit all, click Submit Failed Records.

  2. To submit specific records, select them on the Failed Records tab and click Submit.

  3. A new batch job is automatically created to process resubmitted records.

Note:  If records fail again, resubmit them through the new batch job.


Processing Of Failed Records

When a batch job processes records, only the successfully updated records are saved, while any changes attempted on failed records are undone. This prevents partial updates from occurring in cases where some records succeed and others fail. If all records in a batch are processed without issues, the batch is marked as "completed."Cancel a Batch Job Run

When you cancel a batch job, only unstarted parts are canceled; completed parts remain unchanged. After cancellation, you can view completed parts but not the canceled ones.


Delete a Batch Job Run

  1. In Monitor Workflow Services, locate the batch job of type Flow.

  2. Click Delete next to the batch job and confirm deletion.


Batch Management Limits

You can’t do the following with Batch Management.

  • Select Salesforce Shield encrypted fields in the filter criteria of a batch job.

  • Create multiple versions of a batch job.

  • View the details of the successfully processed records.

  • Run more than five batch jobs simultaneously.

  • Rerun a batch job after it’s complete.


Feature Availability Org Listing Available in Enterprise, and Unlimited Editions with Loyalty Management, Manufacturing Cloud, Rebate Management, or Accounting Subledger. Access to any industry product also gives you access to Batch Management.


Conclusion

In Monitor Workflow Service, you can cancel a batch job run that’s in progress or resubmit the failed records that a completed batch job run failed to process with easy point-and-click tools up to 3 times. The time interval after which a failed batch job part can be anywhere from 1,000 milliseconds to 10,000 milliseconds.


References



Blog Credit:

D. Dewangan

   Salesforce Developer

   Avenoir Technologies Pvt. Ltd.

  Reach us: team@avenoir.ai

Comments


bottom of page