I've created a test which is supposed to create an account, assign a value to a particular field and then test the deletion of the record but fail because of the field value assigned.
My test is failing with this error:
This is my test code - is the test failing because I'm trying to do something I've forbidden in the test script?
@isTest
private class PreventIBISAccountDeletionTest {
@isTest static void TestIBISAccountDeletion() {
//Test data setup
//Create an account with data source set to IBIS & then try to delete it
Account acct = new Account(Name='Trigger Test' , Data_Source__c='IBIS');
insert acct;
// Start test
Test.startTest();
Database.DeleteResult result = Database.delete(acct, false);
Test.stopTest();
// Verify
// In this case the deletion should have been stopped by the trigger,
// so verify that we got back an error.
System.assert(!result.isSuccess());
System.assert(result.getErrors().size() > 0);
System.assertEquals('Cannot delete account with source IBIS.',
result.getErrors()[0].getMessage());
}
}