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
SF Beginner 2019SF Beginner 2019 

single email notification on bulk file upload

Hi, 

I have this trigger that sends an email if something was uploaded on a case. but my problem is how can I achive using the contentdocumentlink, wherein if I upload 5 files, I will only receive 1 email notification using the apex class? because when I upload 5 files I usually receive 5 emails as well. What I want is when I upload 5 files at the same time I will only be receiving one email. Thank you
 
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert, after insert) {
    if(Trigger.isInsert) {
        if(Trigger.isAfter) {
            Set<Id> objectIds = new Set<Id>(); 
            for (ContentDocumentLink a: Trigger.new) {
                String keyPrefix = String.valueOf(a.LinkedEntityId).substring(0, 3);
                if(keyPrefix == '500'){
                    objectIds.add(a.LinkedEntityId);
                }
                ContentDocumentLinkEmailHandler.sendEmailNotification(objectIds);
            }
        }
    }
}
 
public class ContentDocumentLinkEmailHandler {
    public static final string emailTmpltDevName = 'TemplateCase';
 {
 List<Case> caselist = [SELECT Id, Owner.Id,CaseNumber, Subject, Owner.Type FROM Case WHERE Id In: objectIds];
                    for(Case cs:caselist){
                        cs.Send Notification= true;
                    }
                if(caselist.size() > 0)
                {
                    update caselist;
                }
            }
    }
}


 
AnudeepAnudeep (Salesforce Developers) 
Can you please post your code in sendEmailNotification method?