0

When making a test class I've ran into this assertion failure error. FIELD_INTEGRITY_EXCEPTION, ContentDocument ID: id value of incorrect type: 06AP0000001OoEsMAK: [ContentDocumentId]

Here is my test class code:

@isTest
public class LifeLargeCaseReviewCtrlTest {
public static testmethod void NewLLCRCase() {
            
    Account Acc = new Account();
    Acc.Name = 'Test New LLCR Case';
    upsert Acc;
    
    Contact C = new Contact();
    C.AccountId = Acc.id;
    C.FirstName = 'Test First1';
    C.MiddleName = 'Test Middle1';
    C.LastName = 'Test Last1';  
    upsert C;
    
    Lead leadObj = new Lead();
    leadObj.LastName = 'New Claims Lead';
    upsert leadObj;
    
    Case caseObj = new Case();
    caseObj.ContactId = C.id;
    caseObj.Lead__c = leadObj.id;
        
    Case caseObj1 = new Case();
    caseObj1.ContactId = C.id;
    caseObj1.Lead__c = leadObj.id;
    upsert caseObj1;
    
    List<String> policyList = new List<String>();
    Policy__c pol = new Policy__c();
    upsert pol;
    policyList.add(pol.id);
            
    Master_Product__c mp = new Master_Product__c();
    mp.Name = 'Test';
    mp.Active__c = TRUE;
    upsert mp;
    
    Proposed_Purchase__c propObj = new Proposed_Purchase__c();
    propObj.Case__c = caseObj1.id;
    propObj.Add_to_Contract__c = pol.id;
    upsert propObj;  
    
    ContentVersion contentVersion = new ContentVersion();
    contentVersion.Title = 'Test';
    contentVersion.PathOnClient = 'Test.jpg';
    contentVersion.VersionData = Blob.valueOf('Test Content Data');
    contentVersion.IsMajorVersion = true;
    upsert contentVersion;
    List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
    ContentDocumentLink cdl = new ContentDocumentLink();
    cdl.ContentDocumentId = documents[0].Id;
    cdl.LinkedEntityId = caseObj1.id;
    upsert cdl;
    
    Test.startTest();
    LifeLargeCaseReviewCtrl.getInfo(C.id);
    String returnData = LifeLargeCaseReviewCtrl.createLLCRCase(caseObj, policyList, propObj, cdl.Id);
    Test.stopTest();     
    System.assertEquals('Success', returnData, 'Case was not able to be created.');
  }
}

I'm confused how my Id is of the wrong type, or how to fix this error. Any ideas?

Any help is greatly appreciated, thanks!

edit-

here is picture showing the code coverage:

enter image description here

2
  • 1
    IDs of the form 06A... are ContentDocumentLinkIds - see helpful resource. Is the error occurring on the upsert cdl line? or in the code bracketed by Test.start/stopTest? – cropredy Nov 7 '20 at 1:57
  • @cropredy technically the error is occurring on the last line- the assertion. however, if i remove the assertion statement the test passes (false positive) but i don't get enough code coverage, i will edit my original question to show which lines don't pass – sfn00b Nov 7 '20 at 3:43
2

From your screenshot, looks like the fourth argument to the LifeLargeCaseReviewCtrl.createLLCRCase method should be a ContentDocumentid. Instead you are passing in ContentDocumentLink Id. Change LifeLargeCaseReviewCtrl.createLLCRCase(caseObj, policyList, propObj, cdl.Id); to LifeLargeCaseReviewCtrl.createLLCRCase(caseObj, policyList, propObj, documents[0].Id); in your test class

1
  • this solved it!!!!!!!! thank you so much – sfn00b Nov 7 '20 at 4:32
1

I'm not sure that inserting a ContentVersion implicitly creates a ContentDocument that has an id that can be used in a cdl's ContentDocumentId field. Try creating one explicitly.

Also, to see what type of object that id is actually of, try calling

 documents[0].Id.getSobjectType().getDescribe().getName()
1
  • doing this changed the error to System.StringException: Invalid id: ContentDocument – sfn00b Nov 7 '20 at 3:36

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.