You need to sign in to do that
Don't have an account?
Saravana Ravikumar
If there are over 10000 account records , Will the transaction succeed and changes be commited ?
List<Account> accountstoUpdate = new List<Account>();
For(Account thisAccount : [Select id, Status FROM Account LIMIT 50000]){
ThisAccount.Status = ‘Active’;
AccountsToUpdate.add(thisAccount);
}
try{
Database.update(AccountstoUpdate,false);
}catch (Exception e){
System.debug(e.getMessage());
}
For(Account thisAccount : [Select id, Status FROM Account LIMIT 50000]){
ThisAccount.Status = ‘Active’;
AccountsToUpdate.add(thisAccount);
}
try{
Database.update(AccountstoUpdate,false);
}catch (Exception e){
System.debug(e.getMessage());
}
Hi Saravana,
The code snippet you provided attempts to update a list of Account records. However, there are a few considerations regarding the Salesforce governor limits that you should be aware of:
1. Query Limit: In a single transaction, you can query up to 50,000 records. In your code, you are querying 50,000 Account records using a SOQL query with a LIMIT of 50,000. If the total number of Account records in your org exceeds 50,000, this query will exceed the limit and result in a runtime exception.
2. DML Statement Limit: In a single transaction, you can perform DML (Data Manipulation Language) operations, such as inserts, updates, or deletes, on up to 10,000 records. In your code, you are attempting to update the list of Account records, which may include more than 10,000 records. If the total number of records to be updated exceeds 10,000, the update operation will fail and throw a runtime exception.
To handle scenarios where you have a large number of records to update, you can leverage Salesforce's batch apex framework. Batch apex allows you to process large data sets in smaller chunks, adhering to the governor limits.
Here's an example of how you can modify your code to use batch apex:
Trigger the batch job:
In this example, the UpdateAccountStatusBatch class implements the Database.Batchable interface, allowing you to process the Account records in smaller batches. The start method defines the initial query locator, the execute method processes each batch of records, and the finish method handles any post-processing tasks.
By using batch apex, you can efficiently update a large number of records while staying within the Salesforce governor limits.
Hope this will be helpful.
Thanks!