Retrieving Failed Objects from the ExecuteMultipleResponse Method

I am using Execute Multiple Response class to pass in Entity collection for Upsert in Dynamics CRM, I would like to know how to add failed object names to collection and then use exception handling for each of those objects.

+3


source to share


1 answer


Assuming you create yours ExecuteMultipleRequest

something like this:

var entityCollection; // your EntityCollection
var requests = new ExecuteMultipleRequest();

foreach (var entity in entityCollection.Entities) {
    var upsertRequest = new UpsertRequest { Target = entity };
    requests.Requests.Add(upsertRequest);
}

      

You should be able to execute the query, iterate through it, responses

and for each determine if an error occurred:



var responses = service.Execute(requests);
var errors = new List<Entity>();

foreach (var response in responses.Responses) {
    if (response.Fault != null) {
        var entity = entityCollection[response.RequestIndex];
        errors.Add(entity);
    }
}

      

response.RequestIndex

is used to access the corresponding response request by matching their indices.

responses.Responses

contains a set ExecuteMultipleResponseItem

. Documentation about their properties can be found here .

+3


source







All Articles