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

            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.