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
Justin StaugaitisJustin Staugaitis 

caused by: System.DmlException: Update failed. First exception on row 0 with id 0018000001AKu9XAAT; first eror: UNABLE_TrO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 0018000001AKu9XAAT: []

I received the following error message and researched on the forms and the solution seems to be adding UPDATE FOR but I couldnt make that update in SOQL query as I received an error message "Cannot lock rows for an SObject type that can not be updated: AggregateResult"

So im not sure if I need to edit the code where I call List<Account> to an SOQL statement.  See my code below.

ISSUE MESSAGE:

Apex script unhandled trigger exception by user/organization: 0053400000AEv6J/00D80000000PTja
 
accountIssueScore: execution of AfterUpdate
 
caused by: System.DmlException: Update failed. First exception on row 0 with id 0018000001AKu9XAAT; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 0018000001AKu9XAAT: []
 
Trigger.accountIssueScore: line 17, column 1
 
trigger accountIssueScore on Case (after update, after insert) {

        List<AggregateResult> contactAggrList = [SELECT AccountId, SUM(Severity_Value__c) 
                                                 FROM Case 
                                                 WHERE Id IN :Trigger.New
                                                 AND 
                                                 AccountId <> null
                                                 AND Severity__c IN ('Blocker','Critical','Major')
                                                 Group By AccountId FOR UPDATE
                                                 ];

        List<Account> accountsToUPdate3 = new List<Account>();

        for(AggregateResult contactAggr : contactAggrList) {
            accountsToUPdate3.add(new Account(Id = (Id)contactAggr.get('AccountId'),
                                             Issue_Score__c = (Decimal)contactAggr.get('expr0'))); 

        }

        update accountsToUPdate3;
}

​​​​​​​
 
anivesh muppaanivesh muppa

Hi Justin,

There might be the batch process running along with this trigger.

change your batch that is holding the account records that are queried in your trigger, 
do one thing make sure that batch size is less and trigger shouldn't run behind this batch 

modified your logic.

Correct me if I am wrong.

Thank you,

 

Justin StaugaitisJustin Staugaitis
Since im new to APEX chould you help show me what kind of change that would look like in my above code? 
Raj VakatiRaj Vakati
Try this code .. can u check is there a process builders on account object .. if so check what is the entry condition 
 
trigger accountIssueScore on Case (after update, after insert) {

        List<AggregateResult> contactAggrList = [SELECT AccountId, SUM(Severity_Value__c) 
                                                 FROM Case 
                                                 WHERE Id IN :Trigger.newmap.keySet()
                                                 AND 
                                                 AccountId <> null
                                                 AND Severity__c IN ('Blocker','Critical','Major')
                                                 Group By AccountId
                                                 ];

        List<Account> accountsToUPdate3 = new List<Account>();

        for(AggregateResult contactAggr : contactAggrList) {
            accountsToUPdate3.add(new Account(Id = (Id)contactAggr.get('AccountId'),
                                             Issue_Score__c = (Decimal)contactAggr.get('expr0'))); 

        }

        update accountsToUPdate3;
}