You need to sign in to do that
Don't have an account?
Test Class for ContentDocumentLink (Notes)
Hi,
I have a requirement where a field of the parent object changes everytime the user enters a NOTE.
I wrote a trigger on ContentDocumentLink (everytime a ContentDocumentLink record is created, the parent record's field changes) and it's working fine. However my Test Class is not allowing me to create 200 ContentDocumentLink records. Please review the code below and help if you have ever experienced such issues.
It's exceeding the governor limits:
Please note: CA.Id is my parent object (I have already inserted it in my earlier part of the code)
for(Integer a=0;a<200;a++){
Blob beforeblob=Blob.valueOf('Unit Test Attachment Body');
ContentVersion cVersion = new ContentVersion(ContentLocation = 'S', PathOnClient = 'testPath', Title = 'testTitle’+a,
VersionData = beforeblob);
contVerToInsert.add(cVersion);
}
Insert contVerToInsert;
for (ContentVersion cv:contVerToInsert){
mapIndexToContVer.put(Integer.valueOf(cv.Title.remove('testTitle')),cv.Id);
}
for(Integer j=0;j<200;j++){
ContentDocumentLink CDL = New ContentDocumentLink(LinkedEntityId=CA.Id, ShareType = 'V',
ContentDocumentId=mapIndexToContVer.get(j));
notesToInsert.add(CDL);
}
Test.startTest();
Insert notesToInsert;
Test.stopTest();
}
Can you let us know what governer limit it is exceeding?
I tried this piece of code in my org and it got executed with out any issue which means the code is correct except that your logic is assiging content version id to content document in the below line.
I have tried the below code and it worked with out any issue.
I guess your customization is causing some issue there.
If this solution helps, Please mark it as best answer.
Thanks,
Hi Sai, Thanks so much for your help. But, my code is not even running for 90 records... It still says "Too many SOQL queries: 101".
Any idea where this error could be coming from ??
The issue may be because of some trigger on Content document or content document link which is not ready for bulk records.
Thanks,