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:
06A...
are ContentDocumentLinkIds - see helpful resource. Is the error occurring on theupsert cdl
line? or in the code bracketed by Test.start/stopTest? – cropredy Nov 7 '20 at 1:57