You need to sign in to do that
Don't have an account?
tonante
Question Concerning UNABLE TO LOCK
Hi,
I have been getting a few 'unable_to_lock_row' exception when I run Apex Test Execute in Production or Sandbox but when I execute the test cases individually (unit test) they pass.. Even a few of the managed package test cases fail due to this error.
A few of the local test classes all lock on the same object.
Since I have different test classes that need to use this object to test different functionality, My Question is:
Q) Is there a way to avoid this error ?
Q) Would I have to do some sort of asynchronization on the test cases in order for the cases to wait for until he object is free? If so, how do I do this?
Thanks
I have been getting a few 'unable_to_lock_row' exception when I run Apex Test Execute in Production or Sandbox but when I execute the test cases individually (unit test) they pass.. Even a few of the managed package test cases fail due to this error.
A few of the local test classes all lock on the same object.
Since I have different test classes that need to use this object to test different functionality, My Question is:
Q) Is there a way to avoid this error ?
Q) Would I have to do some sort of asynchronization on the test cases in order for the cases to wait for until he object is free? If so, how do I do this?
Thanks
and then you used that code in all of your tests, you would likely run into UNABLE TO LOCK ROW errors because the AccountNumber is suppose to be unique and when there are updates happening on the account object it tries to lock that object but will fail because the external identifier is the same.
To work around this, you should create these external identifiers randomly and use those instead. For example:
If you are not using a TestUtils [1] type class to generate your testing data, I would recommend doing it. This way you would just have to update it in one place instead of all of your tests
[1] http://pcon.github.io/presentations/testing/#testutils-intro
All Answers
and then you used that code in all of your tests, you would likely run into UNABLE TO LOCK ROW errors because the AccountNumber is suppose to be unique and when there are updates happening on the account object it tries to lock that object but will fail because the external identifier is the same.
To work around this, you should create these external identifiers randomly and use those instead. For example:
If you are not using a TestUtils [1] type class to generate your testing data, I would recommend doing it. This way you would just have to update it in one place instead of all of your tests
[1] http://pcon.github.io/presentations/testing/#testutils-intro