title: Dynamics CRM SDK: Execute Multiple Requests for Bulk Update of around 5000 Records
body: <p>I have written a function to update Default Price List for all the Active Products on the CRM 2013 Online.</p>
  
  <pre><code>//The method takes IOrganization service and total number of records to be created as input
  private void UpdateMultipleProducts(IOrganizationService service, int batchSize, EntityCollection UpdateProductsCollection, Guid PriceListGuid)
  {
      //To execute the request we have to add the Microsoft.Xrm.Sdk of the latest SDK as reference
      ExecuteMultipleRequest req = new ExecuteMultipleRequest();
      req.Requests = new OrganizationRequestCollection();
      req.Settings = new ExecuteMultipleSettings();
      req.Settings.ContinueOnError = true;
      req.Settings.ReturnResponses = true;
      try
      {
  
          foreach (var entity in UpdateProductsCollection.Entities)
          {
              UpdateRequest updateRequest = new UpdateRequest { Target = entity };
              entity.Attributes["pricelevelid"] = new EntityReference("pricelevel", PriceListGuid);
              req.Requests.Add(updateRequest);
          }
          var res = service.Execute(req) as ExecuteMultipleResponse;  //Execute the collection of requests
      }
  
          //If the BatchSize exceeds 1000 fault will be thrown.In the catch block divide the records into batchable records and create
      catch (FaultException&lt;OrganizationServiceFault&gt; fault)
      {
          if (fault.Detail.ErrorDetails.Contains("MaxBatchSize"))
          {
              var allowedBatchSize = Convert.ToInt32(fault.Detail.ErrorDetails["MaxBatchSize"]);
              int remainingCreates = batchSize;
  
              while (remainingCreates &gt; 0)
              {
                  var recordsToCreate = Math.Min(remainingCreates, allowedBatchSize);
                  UpdateMultipleProducts(service, recordsToCreate, UpdateProductsCollection, PriceListGuid);
                  remainingCreates -= recordsToCreate;
              }
          }
      }
  }
  </code></pre>
  
  <p>Code Description : There are around 5000 active product records in the System. So I am updating Default Price List for all of them using above code.</p>
  
  <p>But, I am missing here something so that, it has updated only 438 records. It loops through the While statement correctly, but it is not updating all of them here.</p>
  
  <p>What should be the Batchsize when we run this function for the First Time? </p>
  
  <p>Any one can help me here?</p>
  
  <p>Thank you,</p>
  
  <p>Mittal.</p>