C# Dynamics CRM Create Multiple Records using ExecuteMultipleRequest

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

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

Below is sample code:

/// <summary> /// Call this method for bulk Create /// </summary> /// <param name="service">Org Service</param> /// <param name="entities">Collection of entities to Create</param> public static void BulkCreate(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 CreateRequest for each entity to the request collection. foreach (var entity in entities) { CreateRequest createRequest = new CreateRequest { Target = entity }; multipleRequest.Requests.Add(createRequest); } // 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