5

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: []
  • Please post only query part in the question and answer in the answered section. Thanks for sharing info... – Mohith Shrivastava Jan 30 '16 at 1:38
  • sorry @MohithShrivastava - I thought I needed to wait 24 hours to answer my own question. Chagrined. Edits done – cropredy Jan 30 '16 at 2:22
  • Did you create a case with salesforce support for the gack? That would help get it fixed. – Carolyn Grabill Feb 3 '16 at 0:10
  • @CarolynGrabill - yes I did, see meta post here: meta.salesforce.stackexchange.com/questions/2084/… – cropredy Feb 3 '16 at 0:51
4

DIAGNOSIS

The correct and I suspect intended behavior is to generate the message

...Your attempt to delete someName could not be completed because it is associated 
with the following someSobjects ...

for all child SObjects defined in the metadata Schema.ChildRelationship with isRestrictedDelete=true. But, for some reason, the ContentVersion child doesn't play nicely.

This can cause havoc with any delete logic you might have that deletes a parent of ContentVersion, expecting any exception in the delete to be thrown and hence, catchable. Note that in the UI, the Internal Salesforce Error does not occur and, I think, if the ContentVersion was created via the UI, the same above logic run in Execute Anonymous Apex also throws a normal exception.

WORKAROUND

If using code to delete parents of a restrictedDelete child ContentVersion and you are expecting an exception to be thrown and caught, think again. You'll need to explicitly delete the ContentVersion (by deleting the associated ContentDocument) before deleting the ContentVersion's parent.

| improve this answer | |
  • Thank you and no sorry please :)..Thanks again for sharing what you learned with community – Mohith Shrivastava Jan 30 '16 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.