Understanding Salesforce Apex Batch Results Sorting

Question:
While reviewing the Salesforce release updates, I noticed the update titled “Sort Apex Batch Action Results by Request Order”. I couldn’t find much information about what exactly this means. Specifically, what are Apex batch action results? How does this change affect batch operations in Apex? If possible, can you also provide a sample code example that illustrates this behavior?
Answer:
This release update is about how Salesforce returns results from asynchronous Apex batch actions, such as those triggered through the Composite API, Batchable Apex jobs, or Queueable jobs invoked in bulk. Previously, when multiple batch or sub-requests were executed, Salesforce did not guarantee that the response results would be returned in the same order as the requests were submitted. This sometimes caused confusion when you needed to match a particular request to its result.
CRS Info Solutions offers expert Salesforce online training with real-time projects, certification guidance, interview coaching, and a job-ready approach. Enroll for free demo today!!!
With this update, Salesforce ensures that the results are returned in the same order as the requests were made, which makes it easier to process the responses without adding extra logic for ordering.
For example:
if you are running a batch of requests through the Composite API that executes Apex actions, before this update the results may have come back in a different order than you sent them. After the update, they will now be aligned: request 1 → result 1, request 2 → result 2, and so on.
Here’s a simple example using the Composite API with an Apex action:
POST /services/data/v62.0/composite
{
"allOrNone" : false,
"compositeRequest" : [
{
"method" : "POST",
"url" : "/services/data/v62.0/actions/custom/apex/MyAction1",
"referenceId" : "Req1",
"body" : { "recordId" : "001..." }
},
{
"method" : "POST",
"url" : "/services/data/v62.0/actions/custom/apex/MyAction2",
"referenceId" : "Req2",
"body" : { "recordId" : "001..." }
}
]
}Explanation:
This example shows a Composite API request that executes two custom Apex actions in a single call. Each sub-request (MyAction1 and MyAction2) is identified by a referenceId so you can match requests with their results. With the release update, the responses will now be returned in the same order as the requests, making result handling more predictable.
Previously, results from composite or batch requests didn’t always align with the order they were sent, so Req1 might not match the first response. With this release update, Salesforce now guarantees that responses will appear in the same order as the original requests.
For Batchable Apex, the behavior is similar—results are now sorted based on the order the requests were made. This change doesn’t require any code updates but improves predictability and consistency in handling results.
Summing Up
The code demonstrates how Salesforce’s Composite API executes multiple Apex actions in one call while keeping their results tied to unique reference IDs. By setting allOrNone:false, it ensures independent execution, so one failure won’t block the others. This approach improves efficiency and reliability by preserving the order of requests and responses.
Salesforce Training in Chennai: Unlock Your Potential
Elevate your career with our comprehensive Salesforce training in Chennai, designed to equip you with expertise in Admin, Developer, and AI modules. Our program offers unparalleled certification guidance, rigorous interview preparation, and industry-aligned training to ensure you gain a competitive edge. With in-depth modules and expert-led sessions, you’ll build a solid foundation in Salesforce while mastering advanced techniques to meet real-world demands.
Our unique learning approach combines practical hands-on sessions with detailed class notes, enabling you to gain job-ready skills and confidence. Whether you’re starting fresh or upskilling, our training ensures you stand out in the fast-paced Salesforce ecosystem.
Take the first step toward your success by joining our free demo class today and experience the best in Salesforce education!!!

