ExecuteMultipleRequest message in Polaris (CRM 2011)


Using ExecuteMultipleRequest class we can now execute one or more message requests as a single batch.

For example in the code below we are creating 3 contact entity record as well as deleting one of the contact records as a single batch.

Here below, we are first initializing 3 contact entity record, then creating the associated CreateRequest and DeleteRequest.

We are then adding all these requests to OrganizationRequestCollection which we then use for the Requests property of the ExecuteMutlipleRequest class. The request are executed in the order in which they are added to the OrganizationRequestCollection.

Settings Property defines whether execution should continue if an error occurs and if responses for each message request processed are to be returned or not.

// Create 3 contact entitiy's record
Entity entity1 = new Entity("contact");
entity1.Attributes["lastname"] = "lastname1";
Entity entity2 = new Entity("contact");
entity2.Attributes["lastname"] = "lastname2";
Entity entity3 = new Entity("contact");
entity3.Attributes["lastname"] = "lastname3";
// Create CreateRequest and Delete Request
CreateRequest createReq1 = new CreateRequest();
createReq1.Target = entity1;
CreateRequest createReq2 = new CreateRequest();
createReq2.Target = entity2;

// DeleteRequest with incorrect guid to throw error

DeleteRequest deleteReq = new DeleteRequest();
deleteReq.Target = new EntityReference("contact", Guid.NewGuid());

CreateRequest createReq3 = new CreateRequest();
createReq3.Target = entity3;

// Initialize OrganizationRequestCollection

OrganizationRequestCollection orgReqCollection = new OrganizationRequestCollection();
orgReqCollection.Add(createReq1);
orgReqCollection.Add(createReq2);
orgReqCollection.Add(deleteReq);
orgReqCollection.Add(createReq3);

// Intialize ExecuteMultipleRequest

ExecuteMultipleRequest executeMutlipleRequest = new ExecuteMultipleRequest();
executeMutlipleRequest.Requests = orgReqCollection;
executeMutlipleRequest.Settings = new ExecuteMultipleSettings();

// ContinueOnError - specifies whether to continue in case of error in any of the request or not
executeMutlipleRequest.Settings.ContinueOnError = false;

// ReturnResponses - specifies whether to return responses for the requests or not
executeMutlipleRequest.Settings.ReturnResponses = true;

ExecuteMultipleResponse executeMulResponse = (ExecuteMultipleResponse) _service.Execute(executeMutlipleRequest);

In the above example we are deliberately throwing exception for the DeleteRequest.

So if we are setting the ContinueOnError property as false, our program will create the first two contact record and then throws exception.

Contact Records Created:

Exception:

And if we are setting the ContinueOnError as true, our program will create all the three contact records and for the DeleteRequest it will return the error message as a part of response as we have set the ReturnResponses as true.

All the three contact records created:

ExecuteMultipleResponse:

Here we get 4 responses one for each of the requests in OrganizationCollectionRequest.

IsFaulted property of the ExecuteMultipleResponse has value as true as we get a FaultException in case of DeleteRequest.

The Message for the DeleteRequest gives us the error message.

The response for the CreateRequest contains the Guid of the contact record created.


Hope it helps


Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

Author: Nishant Rana

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

One thought on “ExecuteMultipleRequest message in Polaris (CRM 2011)”

Leave a reply to santosh Cancel reply

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

Discover more from Nishant Rana's Weblog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Power Platform Puzzles

D365 CRM, Power Platform Tips &Tricks

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 Microsoft Business Applications 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 - PPUG.ORG

AI - 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

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue

The Professional Paraphraser

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

Power Platform Learning

Your Go-To Resource for Power Apps, Power Automate & More

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.