I recently 'succeeded' in getting an Internal Salesforce Error
aka GACK. Per Josh Kaplan's blog page, I am posting the details and cause in case someone else runs into this before SFDC fixes it. And yes, it took hours to figure this out.
Environment: Sandbox cs21, Unlimited Edition Schema
Account
-----------------------------------
| |
Case ContentVersion
both relationships are defined as restrictedDelete
- meaning, you can't delete the parent before deleting the child. The Account->Cases
relationship comes that way OOB, the Account -> ContentVersion
relationship you have to declare that way in the metadata.
Test Class, same results V35, V36
@isTest
private class FooTest {
@isTest
private static void testGackContentVersion() {
// create two Accounts
Account[] aList = new List<Account>{new Account(name = '00gack'),
new Account(name='01gack')};
insert aList;
// Create a ContentVersion (restrictedDelete on Account->CV relationship is true)
ContentVersion[] cvList = new List<ContentVersion> {
new ContentVersion(title='00_0gack_2020_12_31',
account__c=aList[0].id,
versiondata =Blob.valueOf('fooBody'),
pathOnClient='c:\foo.pdf',
language='en_US')};
insert cvList;
delete aList; // gack occurs here?
}
@isTest
private static void testGackCase() {
// create two Accounts
Account[] aList = new List<Account>{new Account(name = '00gack'),
new Account(name='01gack')};
insert aList;
// Create a Case (restrictedDelete on Account->Cases relationship =true)
Case[] csList = new List<Case> {new Case(accountId = aList[0].id,subject='00_0gack')};
insert csList;
delete aList; // gack occurs here?
}
}
For the deletion of the Account with child ContentVersion (1st testmethod)
Internal Salesforce Error: 1276196940-33783 (-502955608) (-502955608)
For the deletion of the Account with child Case (2nd testmethod)
System.DmlException: Delete failed. First exception on row 0 with id 001q000000QIpshAAD;
first error: DELETE_FAILED, Your attempt to delete 00gack could not be completed because it is associated
with the following cases.: C-00004813: []