Retrieve fault entity IDs when performing ExecuteMultiple
Views (2094)
One of the new features introduced inside CRM 2011 Update Rollup 12 is the ExecuteMultipleRequest message in order to perform bulk data operations. More information can be found at this address:
Use ExecuteMultiple to Improve Performance for Bulk Data Load
When the ContinueOnError property is set to true the service will not stop if there are faults, but how we can retrieve the fault entity IDs?
We need to rely on the RequestIndex property inside ExecuteMultipleResponseItem object, the RequestIndex indicates the corresponding request.
Use ExecuteMultiple to Improve Performance for Bulk Data Load
When the ContinueOnError property is set to true the service will not stop if there are faults, but how we can retrieve the fault entity IDs?
We need to rely on the RequestIndex property inside ExecuteMultipleResponseItem object, the RequestIndex indicates the corresponding request.
ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
{
// assign settings that define execution behavior: continue on error, return responses
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = true,
ReturnResponses = true
},
// create an empty organization request collection
Requests = new OrganizationRequestCollection()
};
// entities to be updated
foreach (var entity in entities)
{
UpdateRequest updateRequest = new UpdateRequest { Target = entity };
updateRequest.RequestId = entity.Id;
requestWithResults.Requests.Add(updateRequest);
}
// execute the bulk update
ExecuteMultipleResponse responseWithResults = (ExecuteMultipleResponse)service.Execute(requestWithResults);
// in this variable we want to store the fault IDs
List<Guid> faultIDs = new List<Guid>();
foreach (ExecuteMultipleResponseItem responseItem in responseWithResults.Responses)
{
// check if the response is fault
if (responseItem.Fault != null)
{
// retrieve the request index
int faultIndex = responseItem.RequestIndex;
// we retrieve the fault ID from the Request collection using the fault index
Guid faultID = requestWithResults.Requests[faultIndex].RequestId.GetValueOrDefault(Guid.Empty);
// store the value
faultIDs.Add(faultID);
}
}
This was originally posted here.

Like
Report
*This post is locked for comments