You need to sign in to do that
Don't have an account?
UNABLE_TO_LOCK_ROW while inserting account recrod in test class
I have the following issue:
While deploying to production, I am encountering multiple test class failures, reproting the UNABLE_TO_LOCK_ROW error.
The failure is when the test class is trying to create an account record for testing - the error is thrown when trying to insert an account record.
When running all tests in a sandbox, the issue does not occur. I was able to test the deployment to a full sandbox with no issue, it's just the production environemnt that is failing.
I read the FAQs and trying switching off all autonumber and external id fields, but that did not make any difference. I don;t have any roll up summery fields, I'm not using any multi-threading, so can;t really find any other issue related to an 'insert' statment
I tried SFDC support, which refered me to the FAQ (that's premier support money well spent)
I'll attach an exrept of the log file, the class cuasing the issue and the account metadata file
'd appraciate any idea as we are currently stuck with this deployment ...
Error log (I am using a bamboo script, deploying from a bitbucket repo):
BUILD FAILED
/var/lib/bamboo/xml-data/build-dir/HM-HM-JOB1/ci_tool/ant/deploy_code.xml:17: FAILURES:
Test failure, method: TestAccountDataCreationUtility.testCreateAndInsertAccountForLastEffectiveCallDateTests -- System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] stack Class.AccountDataCreationUtility.createAndInsertAccountForLastEffectiveCallDateTests: line 34, column 1
Class.TestAccountDataCreationUtility.testCreateAndInsertAccountForLastEffectiveCallDateTests: line 36, column 1
Test failure, method: TestAccountDataCreationUtility.testCreateAndInsertAccountForTests -- System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] stack Class.AccountDataCreationUtility.createAndInsertAccountForTests: line 8, column 1
Class.TestAccountDataCreationUtility.testCreateAndInsertAccountForTests: line 6, column 1
Test failure, method: TestAccountDataCreationUtility.testCreateAndInsertAccountsForTests -- System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] stack Class.AccountDataCreationUtility.createAndInsertAccountsForTests: line 23, column 1
Class.TestAccountDataCreationUtility.testCreateAndInsertAccountsForTests: line 18, column 1
Test failure, method: TestAccountTrigger.testInvalidBillingCountryThrowsErrorOnUpdate -- System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] stack Class.AccountDataCreationUtility.createAndInsertAccountForTests: line 8, column 1
Class.TestAccountTrigger.testInvalidBillingCountryThrowsErrorOnUpdate: line 15, column 1
Test failure, method: TestAccountTrigger.testValidBillingCountryDoesntThrowErrorOnUpdate -- System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] stack Class.AccountDataCreationUtility.createAndInsertAccountForTests: line 8, column 1
Class.TestAccountTrigger.testValidBillingCountryDoesntThrowErrorOnUpdate: line 25, column 1
This is the test class causing the errors (it works in production - it only fails once the new payload is deployed):
@isTest
public with sharing class AccountDataCreationUtility {
public static Account createAndInsertAccountForTests() {
Account account = createAccount();
insert account;
return account;
}
public static List<Account> createAndInsertAccountsForTests(Integer recordCount) {
List<Account> accounts = new List<Account>();
for (integer i = 0; i < recordCount; i++) {
Account account = createAccount();
account.Name += string.valueOf(i);
accounts.add(account);
}
insert accounts;
return accounts;
}
public static Account createAndInsertAccountForLastEffectiveCallDateTests(Date LastEffectiveCallDate) {
Account account = createAccount();
account.Last_Effective_Call_Date__c = LastEffectiveCallDate;
insert account;
return account;
}
public static Account createAccount() {
Country__c country = CountryDataCreationUtility.createAndInsertCountryForTests();
Account account = new Account (
Name = 'Default Test Account' + DateTime.now().getTime() + country.Id,
ShippingCountry = country.Name,
Phone = '+442071833893'
);
return account;
}
public static Account createAccountValidFieldEntries() {
Country__c country = CountryDataCreationUtility.createAndInsertCountryForTests();
Account account = new Account (
Name = 'Default Test Account ' + country.Id,
ShippingCountry = country.Name,
Phone = '+442071833893'
);
return account;
}
}
post also new payload class & it's test class
Hi Marko - the class posted is the new class :-)
the new payload contains 647 oblects, however the failure is for the 'createAccount' test class method, consistently
I can't paste the account obect xml itself as it is too big ...
To temporarily circumvent this issue, on Apex Test Execution page click options and tick Disable Parallel Apex Testing. Then the testing will take longer but you won't get the error.