I want a test class like:
if system.runAs(user) {
Test.startTest();
delete new List<Sobject>(); // should give error.
Test.stopTest();
}
How can I do this in my test class?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI want a test class like:
if system.runAs(user) {
Test.startTest();
delete new List<Sobject>(); // should give error.
Test.stopTest();
}
How can I do this in my test class?
I usually prefer to use the following pattern when you need an all-or-none test:
try {
delete records;
System.assert(false, "Expected DMLException");
} catch(DMLException e) {
// Validate specific errors here
}