Hi Roman, Try with below code and replace your custom object name.
If this helps, Please mark it as best answer.Thanks!!trigger documentcheck on ContentDocumentLink (before insert) {
Set<Id> parentQuoteDocumentIds = new Set<Id>();
for(ContentDocumentLink cdl : Trigger.new){
parentQuoteDocumentIds.add(cdl.LinkedEntityId);
}
List<ContentDocumentLink> CDLList = new List<ContentDocumentLink>([SELECT id, LinkedEntityId fROM ContentDocumentLink WHERE LinkedEntityId IN : parentQuoteDocumentIds]);
for(ContentDocumentLink a : Trigger.new) {
if(CDLList.size()>0 && (a.LinkedEntityId).getSObjectType().getDescribe().getName() == 'Customobject__c' ) {
a.addError('You cannot add More than one file');
}
}
}
2 answers