Hi Raja You don't have to do anything extra on the lightning page. In your trigger do accountObject.addError('Your Error Message'). The message should be visible on the account record in lightning. Pradeep
@pradeep: I am trying to upload attachment in lightning from account record related list however did not getting error.. as per below trigger i should not allow to upload pdf content and show error..Its working perfectly to stop uploading but did not showing error message to me/...
You don't have to do anything extra on the lightning page. In your trigger do accountObject.addError('Your Error Message').
The message should be visible on the account record in lightning.
Pradeep
trigger ContentDocumentLinkTrigger on ContentDocumentLink (after insert) {
Set<Id> Ids = new Set<id>();
Map<Id,ContentDocumentLink> mapcvwithid = new Map<Id,ContentDocumentLink>();
for(ContentDocumentLink c:Trigger.new){
ids.add(c.ContentDocumentId);
mapcvwithid.put(c.ContentDocumentId,c);
}
if(ids.size() > 0){
for(ContentDocument ContentDocumentObj : [select id,ContentDocumentId,FileType from ContentDocument where contentdocumentid in: ids]){
if(mapcvwithid.get(ContentDocumentObj.Id).LinkedEntityId != null && ContentDocumentObj.FileType != null){
String ObjectName = mapcvwithid.get(ContentDocumentObj.Id).LinkedEntityId.getSObjectType().getDescribe().getName();
String filetype = String.toLowerCase(ContentDocumentObj.FileType);
String CsName = ObjectName+'-'+filetype;
if(FilesExtensionAllowed__c.getInstance(Csname) != null && FilesExtensionAllowed__c.getInstance(Csname).Name.substringBefore('-') == ObjectName && FilesExtensionAllowed__c.getInstance(Csname).Name.substringAfter('-') == filetype){
ContentDocumentLink ContentDocumentLinkObj = mapcvwithid.get(ContentDocumentObj.Id);
ContentDocumentLinkObj.addError('Testing error');
}
}
}
}
}
What is the need for this trigger to be after insert?