I have been building more code that touch products and as such am referring to the standard pricebook with my test classes (I create products and pricebook entries related to the standard pricebook).
What I'm finding is that if I run my test classes in parallel sometimes they would fail with:
UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record
However, if I run them separately they pass as expected. is there a way to refer to the standard pricebook id without locking the record for the other tests? I have 3 tests that reference the pricebook with Test.getStandardPricebookId() but they keep tripping over each other.
insert
withupsert
. Lastly, you can inject some randomness in record names withMath.random
.