Dynamics CRM Update Multiple Records C#

To avoid calling OrganizationService.Update multiple times. By using ExecuteMultipleRequest we can update a bunch of records at a time. Dynamics CRM Update Multiple Records C#

Max patch size is 1000. You can update 1000 records per request

Below is sample code:

/// <summary> /// Call this method for bulk update /// </summary> /// <param name="service">Org Service</param> /// <param name="entities">Collection of entities to Update</param> public static void BulkUpdate(IOrganizationService service, DataCollection < Entity > entities) { // Create an ExecuteMultipleRequest object. var multipleRequest = new ExecuteMultipleRequest() { // Assign settings that define execution behavior: continue on error, return responses. Settings = new ExecuteMultipleSettings() { ContinueOnError = false, ReturnResponses = true }, // Create an empty organization request collection. Requests = new OrganizationRequestCollection() }; // Add a UpdateRequest for each entity to the request collection. foreach(var entity in entities) { UpdateRequest updateRequest = new UpdateRequest { Target = entity }; multipleRequest.Requests.Add(updateRequest); } // Execute all the requests in the request collection using a single web method call. ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)service.Execute(multipleRequest); }
Code language: PHP (php)

Leave a Reply