
Handling large-scale data tasks in Dynamics 365 CRM can be challenging, especially when syncing thousands of records with external systems. Background Operations allow these resource-intensive tasks to run asynchronously, keeping the system responsive.
In this article, we’ll walk through the technical setup using a practical scenario: syncing thousands of records with an external system. You’ll learn how to create a Background Operation and use a Callback URL to get notified or trigger other processes automatically once the job completes.
For insights into synchronous vs asynchronous workflows and why Background Operations are essential for large data sets, refer to Part 1.
Many organizations use both Dynamics 365 CRM and an external ERP system, requiring regular synchronization of all customer and order data. This includes not only the records themselves but also related data in the external system.
Using a Background Operation allows this process to run asynchronously, without affecting other running processes. It also supports a Callback URL, which notifies the administrator automatically once the operation is completed, eliminating the need for manual monitoring.
With a Background Operation, all syncing logic can be consolidated into a single request, allowing Dynamics 365 to run the large job in the background without disturbing users, while automatically informing the system or administrators when the task is finished.
To implement this in Dynamics 365, a Custom API containing the sync logic must be created and triggered via the ExecuteBackgroundOperation request.
Create a Custom API in Dynamics 365 called SyncRecordsToExternalSystem. Back it with a plugin, which handles:
This plugin runs in the background, removing timeout limitations and efficiently processing thousands of records.
Next, you need a way to call your new Custom API. The key is that instead of executing your Custom API directly, you wrap it in an ExecuteBackgroundOperation request.
This tells Dynamics 365 to take your request (the asyncRequest) and run it as a background job, giving you back a BackgroundOperationId to track it.
Here is a C# code snippet, similar to the one from Part 1, but this time we are calling our new Custom API. This code would typically run in another plugin (e.g., on a scheduled job or button click).
public void Execute(IServiceProvider serviceProvider)
{
// Services
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service =
serviceFactory.CreateOrganizationService(context.UserId);
try
{
tracingService.Trace("Starting background sync operation...");
// 1. Create the request for your Custom API that syncs records.
var asyncRequest = new OrganizationRequest("sample_SyncRecordsToExternalSystem")
{
Parameters =
{
// You can pass parameters to your logic,
{"EntityName", "account"},
{"SyncMode", "Incremental"},
{"ExternalSystemUrl", "https://api.erpsystem.com/v1/customers"},
{"LastSyncDate", DateTime.UtcNow.AddDays(-1)}
}
};
// 2. Create the request to execute your Custom API in the background.
var request = new OrganizationRequest("ExecuteBackgroundOperation")
{
Parameters =
{
{"Request", asyncRequest },
// 3. Request a callback. This is a Power Automate Flow URL.
// This flow will be triggered when the job is done.
{"CallbackUri", "https://prod-123.westeurope.logic.azure.com/workflows/..." }
}
};
// Execute the background operation request
var response = service.Execute(request);
// This ID lets you monitor the job in the "Background Operations" view
tracingService.Trace($"BackgroundOperationId: {response["BackgroundOperationId"]}");
tracingService.Trace($"Location: {response["Location"]}");
}
catch (Exception ex)
{
tracingService.Trace($"Exception: {ex.Message}");
throw new InvalidPluginExecutionException("Sync background job failed.", ex);
}
}
You can monitor the progress under Advanced Settings → Settings → System Jobs → Background Operations, where you can view status, duration, parameters, and error logs easily.
This is where the magic happens. Your duplicate job might take 30 minutes, 4 hours, or even a whole day. You don’t want to sit and watch the “System Jobs” screen.
The CallbackUrl you provided (e.g., the URL for a Power Automate HTTP-triggered flow) will be called automatically by Dynamics 365 the moment the operation finishes.
Your Power Automate flow can then:
Handling large-scale integration operations can be challenging, but Dynamics 365 provides the right tools to manage them efficiently. By combining Custom APIs with the ExecuteBackgroundOperation message, you can safely run heavy, resource-intensive tasks like external system synchronization without affecting users or system performance.
With the CallbackUrl, Dynamics 365 automatically notifies you once the background job is completed. It can trigger actions like sending a summary email, logging results, updating dashboards, or scheduling the next sync, removing the need for manual monitoring.
What are Background Operations in CRM?
Background Operations in Dynamics 365 CRM are asynchronous processes that run in the background, allowing long-running or resource-intensive tasks to execute without slowing down the system. They are ideal for bulk updates, data migration, or integration with external systems.
How does a Callback URL work in CRM?
A Callback URL is an endpoint (like a Power Automate flow, webhook, or API) that Dynamics 365 CRM automatically calls when a Background Operation completes. It enables automatic notifications, follow-up workflows, dashboard updates, or error handling.
Why are asynchronous workflows better for large data sets in Dynamics 365?
Asynchronous workflows, such as Background Operations, prevent system slowdowns or timeout errors when processing thousands of records. Unlike synchronous workflows, they allow users to continue working while large data operations run in the background.
Can Background Operations sync data with external systems?
Yes. Background Operations in Dynamics 365 CRM can execute custom APIs to synchronize records with external ERP or other third-party systems efficiently, ensuring data consistency and minimal disruption to users.
How can administrators monitor Background Operations?
Administrators can monitor Background Operations under Advanced Settings → System Jobs → Background Operations, checking status, parameters, duration, and error logs for each job.
The post A Practical Guide to Background Operations and Callback URL in Dynamics 365: Part 2 first appeared on Microsoft Dynamics 365 CRM Tips and Tricks.
Original Post https://www.inogic.com/blog/2025/11/a-practical-guide-to-background-operations-and-callback-url-in-dynamics-365-part-2/






