Using Parallel ForEach and ExecutionTransactionRequest in CRM 2015 for bulk creation of records.

Hi,

Recently we had a requirement to read each account record and create 4 related child records for each of them. First we wrote a console app that will loop through each of the account records and will create corresponding records. The tool was working fine however it’s execution was very slow. It was talking around 5 hours to process 10000 Account records and create corresponding 40000 child records.

To fine tune the performance, we implemented the Parallel.ForEach.

We got the performance improvement, however we were getting the following error

The communication object, System.ServiceModel.Security.TransportSecurityProtocol, cannot be used for communication because it has been Aborted.

And because of this we had few Account records which had one, two or three records instead of total 4 related records as required. (as the child records might be getting created by separate thread).

For e.g. we can see that for Account Number 98208 we have four records created one at 8:33, then another one at 8:36, 8:38 and 8:41. (gap of minimum 2 minutes). So if there was an exception we had account records created with less than 4 child records.

We solved this issue by using ExecuteTransactionRequest, and creating all the child records as part of transaction, so that we either have all the 4 records created or none.

All the child records were getting created at the same time

We also got huge performance improvement, the code that was initially taking 5 hours to process 10000 records, were not taking only 1 hour to process them.

Few points to remember :-

  • ExecuteMultipleRequest can contain ExecuteTransactionRequest and not vice versa.
  • Batch Size of 1000 applies to both. In Online it is 2.
  • ExecuteTransactionRequest can have mix of Create and Update Request.

Hope it helps..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

2 thoughts on “Using Parallel ForEach and ExecutionTransactionRequest in CRM 2015 for bulk creation of records.”

  1. Hi Nishant,
    Nice article.
    You can split records of 1000 or 2000 each and send request at a time using execute multiple , it will take less time .One web request how many records you are sending using execute multiple

    Like

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s