Salesforce doc states when you delete an Account, its children orders are deleted
But: If you do this in an org with a real Account and a draft Order, when you delete the Account, you get this error:
Your attempt to delete MyAccount could not be completed
because it is associated with the following orders.: 00433894
So, for sake of argument, let's assume the doc is wrong
Now, here is where it gets weird...
Consider an APEX testmethod that deletes an Org Account w/ Order
@IsTest (SeeAllData=true)
static void testAccountDeleteWithOrgOrder() {
Database.DeleteResult[] results =
Database.delete(new List<Account> {new Account(Id='0016300000eqXLkAAM')},false);
System.debug(LoggingLevel.INFO,'results='+results);
}
The delete fails (just like a delete from the UI) with results showing:
Database.DeleteResult[getErrors=(Database.Error[getFields=();
getMessage=Your attempt to delete 1563488920160 could not be completed
because it is associated with the following orders.: 00433894
Same thing as above happens if you run the Database.delete
code in anonymous Apex.
But if your testmethod mocks the Accounts and child Order (as one would normally do)
@IsTest
static void testAccountDeleteWithMockOrder() {
Account a = new Account(Name = 'mockAccount');
insert a;
Order o = new Order(AccountId = a.Id, EffectiveDate = Date.today(), Status = 'Draft');
insert o;
Database.DeleteResult[] results = Database.delete(new List<Account> {a},false);
System.debug(LoggingLevel.INFO,'results='+results);
}
Here, in the testmethod with mocked Accounts and Orders, the delete succeeds !?!
results=(Database.DeleteResult[getErrors=();getId=0016300000vIQUjAAO;isSuccess=true;])
Why doesn't the testmethod (V50) behave the same as PROD (also V50)?