You need to sign in to do that
Don't have an account?

before trigger on ContentDocumentLink throwing error
Hello All,
I am writting trigger on ContentDocumentLink but while uploading file I am getting below error. need help please.

I am writting trigger on ContentDocumentLink but while uploading file I am getting below error. need help please.
trigger tesDocUpload on ContentDocumentLink (before insert) { List<string> strIds = trigger.newmap.keyset() ; List<ContentDocumentLink> lstContDoc= [Select Id,ContentDocumentId From ContentDocumentLink where LinkedEntityId IN: strIds ]; for(ContentDocumentLink cd : lstContDoc){ if(lstContDoc.size() > 3){ cd.addError('Only 3 files can be uploaded!'); } } }
--
Naveen
Add null check to for loop and test with a different set of records[with size of 0, 2 and 3] and see if it is throwing that error.
Hope it will resolve your issue. Update the status.
--
Naveen
Team codengine.in
trigger tesDocUpload on ContentDocumentLink (before insert) {
try{
Set<Id> strIds = trigger.newmap.keyset() ;
List<ContentDocumentLink> lstContDoc= [Select Id,ContentDocumentId From ContentDocumentLink where LinkedEntityId IN: strIds ];
System.debug('lstContDoc-->'+lstContDoc);
for(ContentDocumentLink cd : lstContDoc){
if(lstContDoc.size() > 3){
cd.addError('Only 3 files can be uploaded!');
}
}
}catch (DmlException dee)
{
System.debug('DmlException Message' + dee.getLineNumber() + 'DmlException Message = ' +dee.getMessage());
}catch (Exception ee) {
System.debug('Exception Message' + ee.getLineNumber() + 'Exception Message = ' + ee.getMessage());
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha