Announcements
I have a plugin that I an using to delete opportunity products and its taking forever to run and times out due to the 2min plugin limit.
My Opportunity contains 423 Opportunity Products, is there a better way to delete all products on the opportunity?
I commented out all other transactions in the plugin till only the below remained and was still timing out.
public void DeleteProducts(IOrganizationService dynamicsService, ITracingService tracingService, EntityCollection opp_prod) { tracingService.Trace("DeleteProducts"); foreach (Entity product in opp_prod.Entities) { DeleteRequest deleteReq = new DeleteRequest() { Target = product.ToEntityReference() }; dynamicsService.Execute(deleteReq); } }
I tried to switch to something like the below, the Action in this example calls a plugin (Async) to process each of the batches, then i was hit with the error "1205 Transaction (Process ID %d) was deadlocked on %.*ls resources with another process and has been chosen as the deadlock victim. Rerun the transaction."public void DeleteProducts(IOrganizationService dynamicsService, ITracingService tracingService, EntityCollection opp_prod)
{
tracingService.Trace("DeleteProducts");
OrganizationRequest req = new OrganizationRequest("c1_RecordCreateOrDeleteAction");
req["Action"] = "Delete";
req["Message"] = "Attempted deletion of Opportunity Line Items";
int batchSize = 20;
//split the records into batches of defined size to prevent more time outs
List lstWrapper = new List();
for (int i = 0; i < (opp_prod.Entities.Count / batchSize) 1; i )
{
EntityCollection batchCollection = new EntityCollection();
batchCollection.EntityName = "opportunityproduct";
for (int j = (i * batchSize); (j < (i * batchSize) batchSize) && j < opp_prod.Entities.Count; j )
{
Entity current = opp_prod.Entities.ElementAt(j);
batchCollection.Entities.Add(current);
}
lstWrapper.Add(batchCollection);
}
if (lstWrapper.Any())
{
tracingService.Trace("number of batches to process - " lstWrapper.Count());
foreach (EntityCollection batchToProcess in lstWrapper)
{
req["Records"] = batchToProcess;
OrganizationResponse response = dynamicsService.Execute(req);
}
}
}
Ideally i want the delete to take seconds not minuets or some way to delete a list of opportunity product and create new ones in parallel without locking.
Unfortunately I tried that already, same issue with time out (works on opportunitys will less products), the Microsoft documentation also tells us not to use ExicuteMultiple in plugins -
docs.microsoft.com/.../avoid-batch-requests-plugin
Tried splitting the multiple request into smaller batches similar to the above but get lock issues again even though the same item is never accessed multiple times.
Struggling with this one, don't understand why Microsoft is so slow here.
Hi,
Can you try using Execute multiple request to delete records
docs.microsoft.com/.../execute-multiple-requests
This will reduce the number of service calls and should increase the performance of your plugin.
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156