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
Raja Bhandari 16Raja Bhandari 16 

How to show trigger generated adderror message on account record in lightning?

Pradeep JonnalagaddaPradeep Jonnalagadda
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
Raja Bhandari 16Raja Bhandari 16
@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/...

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');
                }
            }
        }
    }
}
Pradeep JonnalagaddaPradeep Jonnalagadda
Only before Insert triggers display the message on the UI. After Inserts don't.
What is the need for this trigger to be after insert?

 
Raj VakatiRaj Vakati
try this 
 
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before 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');
                }
            }
        }
    }