web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Execute Multiple Request, Maximum Size

(0) ShareShare
ReportReport
Posted on by 605

Hi All,

I am performing an update in CRM via Execute Multiple Request as stated below. I am retrieving more than 1000 records from excel and updating it in CRM. 

ExecuteMultipleResponse mulresponse = (ExecuteMultipleResponse)_service.Execute(multipleReq);

I have more than 1000 records to be processed. 

I am not sure as to how to handle this.

Regards,

Rahul

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Rahul ,

    Batch size limit is 1000. If you add more than 1000 it will throw a fault exception.

    Please refer below-

    [View:https://sreenipavalla.wordpress.com/2015/01/06/limitations-of-execute-multiple-request/]

  • Rahul G J Profile Picture
    605 on at

    Hi Goutam,

    I read about it, i wanted to know how to process the remaining records after 1000th record.

    Regards,

    Rahul

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
  • Rahul G J Profile Picture
    605 on at

    Hi Goutam,

    Is this supported in CRM 365 Online.

    Regards,

    Rahul

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi Rahul,

    try some thing like this. This is pseudo code.

    // Create Entity Collection for update 
                EntityCollection entityCollection = new EntityCollection();
    
    foreach (var item in items){
    Collection(item, service);
    }
    public void Collection(entity, service){ if (entityCollection.Entities.Count< 990) { // Add entities in Collection entityCollection.Entities.Add(entity); } else {
    // call batch request UpdateRequest(service, entityCollection); entityCollection = new EntityCollection(); entityCollection.Entities.Add(entity); }
    }
    public void UpdateRequest(IOrganizationService service, EntityCollection entityCollection)
            {
                ExecuteMultipleRequest executeMultipleRequest = null;
                try
                {
                    #region Execute Multiple with No Results
    
                    executeMultipleRequest = new ExecuteMultipleRequest()
                    {
                        // Set the execution behavior to not continue after the first error is received
                        // and to not return responses.
                        Settings = new ExecuteMultipleSettings()
                        {
                            ContinueOnError = false,
                            ReturnResponses = false
                        },
                        Requests = new OrganizationRequestCollection()
                    };
    
                    // Update the entities that were previously created.
                    EntityCollection update = entityCollection;
    
                    foreach (var entity in update.Entities)
                    {
                        UpdateRequest updateRequest = new UpdateRequest { Target = entity };
                        executeMultipleRequest.Requests.Add(updateRequest);
                    }
    
                    ExecuteMultipleResponse responseWithNoResults =
                        (ExecuteMultipleResponse)service.Execute(executeMultipleRequest);
    
                    // There should be no responses unless there was an error. Only the first error 
                    // should be returned. That is the behavior defined in the settings.
                    if (responseWithNoResults.Responses.Count > 0)
                    {
                        foreach (var responseItem in responseWithNoResults.Responses)
                        {
                            if (responseItem.Fault != null)
                                DisplayFault(executeMultipleRequest.Requests[responseItem.RequestIndex],
                                    responseItem.RequestIndex, responseItem.Fault, service);
                        }
                    }
                    else
                    {
                        //Console.WriteLine("All account records have been updated successfully.");
                    }
    
                    #endregion Execute Multiple with No Results
                }
    
                catch (FaultException<OrganizationServiceFault> fault)
                {
                    // Check if the maximum batch size has been exceeded. The maximum batch size is only included in the fault if it
                    // the input request collection count exceeds the maximum batch size.
                    if (fault.Detail.ErrorDetails.Contains("MaxBatchSize"))
                    {
                        int maxBatchSize = Convert.ToInt32(fault.Detail.ErrorDetails["MaxBatchSize"]);
                        if (maxBatchSize < executeMultipleRequest.Requests.Count)
                        {
                            // Here you could reduce the size of your request collection and re-submit the ExecuteMultiple request.
                            // For this sample, that only issues a few requests per batch, we will just print out some info. However,
                            // this code will never be executed because the default max batch size is 1000.
                            //Console.WriteLine("The input request collection contains %0 requests, which exceeds the maximum allowed (%1)",
                            //    executeMultipleRequest.Requests.Count, maxBatchSize);
                        }
                    }
                    // Re-throw so Main() can process the fault.
                    throw;
                }
            }
    




    Thanks

    Justin Jose

  • Martin Donnelly Profile Picture
    1,030 on at

    This shows paging.  I leave it to you to form a batch for every 200 (1000 is not a magic number -- in fact, smaller batches are better):

               QueryExpression q = new QueryExpression(logicalname);

               q.ColumnSet = new ColumnSet(true);

               q.Criteria = new FilterExpression();

               q.PageInfo = new PagingInfo();

               q.PageInfo.Count = 200;

               q.PageInfo.PageNumber = 1;

               q.PageInfo.PagingCookie = null;

               EntityCollection recs = fromService.RetrieveMultiple(q);

               System.Console.WriteLine("{0} {1} to complete", logicalname, recs.Entities.Count == 0 ? "none" : recs.Entities.Count.ToString());

               while (recs.Entities != null) {

                   ...

                   if (recs.MoreRecords) {

                       q.PageInfo.PageNumber++;

                       q.PageInfo.PagingCookie = recs.PagingCookie;

                       recs = fromService.RetrieveMultiple(q);

                       System.Console.WriteLine();

                   }

                   else

                       break;

               }

               System.Console.WriteLine();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans