Tuesday, January 22, 2013

Using ExecuteMultipleRequest with CRM 2011

ExecuteMultipleRequest METHOD IN ACTION

As we all know CRM 2011 rollup 12 has lunched a new ExecuteMultipleRequest method.
Today i am just exploring this great feature and develop a code snippets and wants to share with you.
Note: Make sure you have latest SDK of CRM 2011

            var service = new XrmServiceContext("Xrm");
            OrganizationRequestCollection collection = new OrganizationRequestCollection();
            for (int i = 0; i <= 5000; i++)
            {
                CreateRequest createRequest = new CreateRequest // create a request and add the request in collection
                {
                    Target = GetEntityRecord()    // this method could returns any entity i.e account, contact etc you could implement your own logic to get the target entity
                };
                collection.Add(createRequest);
            }

            ExecuteMultipleRequest excuteMultipleRequest = new ExecuteMultipleRequest // Create ExecuteMultipleRequest object with the above collection
            {
                Requests = collection,
                Settings = new ExecuteMultipleSettings
                {
                    ContinueOnError = false,
                    ReturnResponses = true
                }
            };
            ExecuteMultipleResponse executeMultipleResponse = (ExecuteMultipleResponse)service.Execute(excuteMultipleRequest); //Execute the request
            var results = executeMultipleResponse.Results; //Request result


I hope it helps some one.

2 comments:

  1. Hi, I tried to implement this ExecuteMultipleRequest in my plugin. But I could not found any dll which has this method even with latest SDK. Can you please let me know what reference I should use here?

    ReplyDelete
    Replies
    1. Hi Charan Raju.
      Please check the following link and rebuild your solutions
      These are the Namespace which is required for ExecuteMultipleRequest.
      Namespace: Microsoft.Xrm.Sdk.Messages
      Assembly: Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)
      http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.executemultiplerequest.aspx

      Delete