function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suresh sanneboina 4suresh sanneboina 4 

When i do a merge operation. i am getting the Exception (Too Many DML Rows 10001). salesforce has a limit of 10000 per single transaction. How can i overcome this issue.

Hi,

We have created a global web service class and that has a method which accepts parameters
Source Account Id and target account id. The source needs to be merged to target and all the contacts(14000) existing in source should be moved to target. Before moving the contact i need to update contacts and need to merge. We are getting the exception 'Too Many DML Rows
10001'.

I knew that salesforce has a DML limit of 10000 rows in a single transaction. I cannot use asynchronous call since the request to merge the records is called from the External System.

Please help me out if there is any alternative.

 
JethaJetha
So basically you are trying to update AccountId field of Contact object with the new target Account Id.

Asynchronous call is quite possible in this case also, either batch apex or future call will work.

Can you please let us know what you are returning from your webservice method, That will help us to understand better.
suresh sanneboina 4suresh sanneboina 4
In the webservice method which i am calling to merge. once the merge operation is done. we are sending response back to the service. Whether the merge is successfull or not. 

Since we are getting the (too Many DML Rows 10001) errors. We are unable to make the transaction successfull in the external application.
JethaJetha
if you want to process more than 10000 record in a single transaction, that is not possible through synchronous call. Either you can call your webservice methos multiple time if records to be processed is more than 10000, or use asynchronous call.
venkat-Dvenkat-D
another way can is to update 10000 records first and then send response to webservice which can tell if there are more contacts to update. Then make another webservice all to update remianing records. This way your total process is atleast synchronous.