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 the 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, was now 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 the max parallel request could be 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 !

6 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

  2. Hey Nishant, Is it possible to do parallel.for in plugin ??

    Bizarre question with lot of eyebrows raised – but dare i ask is that possible ? I have a scenario where around 250 child records and a parent record to be created in a sync model

    Liked by 1 person

Please share your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM