bulk Create/Update/Delete for Dynamics 365

 Secret

Create / Update / Delete can be done with bulk operation, to avoid more DB hits and it will improve performance of the plugins and or code.

Here is reference MSDN URL http://msdn.microsoft.com/en-us/library/jj863631.aspx

Default max batch size is 1000, its applicable for all three create/update/delete.

  1. bulk Create can be done with following code snippet
CreateRequest createRequest = new CreateRequest { Target = 'your Entity Object' };

2. bulk Update can be done with following code snippet

UpdateRequest updateRequest = new UpdateRequest { Target = 'your Entity Object' };

3. bulk Delete can be done with following code snippet

DeleteRequest deleteRequest = new DeleteRequest { Target = 'your Entity Reference Object' };

Here are sample code blocks for bulk Update

 

Create multiple execute request

/// <summary>
 /// Create an ExecuteMultipleRequest object
 /// </summary>
 /// <returns></returns>
 private static ExecuteMultipleRequest CreateBulkExcuteRequest()
 {
 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()
 };
 return multipleRequest;
 }

Continue reading “bulk Create/Update/Delete for Dynamics 365”