function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
German Mejias 7German Mejias 7 

AfterInsert Trigger on ContentDocumentLink addError not working

In Apex using a AfterInsert Trigger over ContentDocumentLink (cdl) object, the method cdl.addError ('Custom message') is not working as expected. 
According to standard documentation https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocumentlink.htm using a cdl.addError ('Custom message') should show a custom message error to the user (Standard lightning component Notes)
This is not the case. Instead the error that is showing is just standard error that provide no information to the user.
trigger cdlTrigger on ContentDocumentLink (after insert) {
    for (ContentDocumentLink cdl : trigger.new) {
        if (!CDLHelper.isSharingAllowed(cdl)) {
            cdl.addError('Sorry, you cannot share this file.');
        }
    }
}

public class CDLHelper {
    public static boolean isSharingAllowed(ContentDocumentLink cdl) {
       return false;
    }

}

 
Brian DyerBrian Dyer

Hi, I'm having the same problem.  The lightning UI simply displays "Can't upload <fileName.ext>."

Have you found a workaround?

sfdcdudesfdcdude
Is there any workaround or solution for the above mentioned question. I am also in much need for the same soultion.