0

I have a custom form that when hit submit button. Then an email alert will be send to Record Owner. And in my form I have using <lightning: fileUpload> to upload file to record.

I want to know is that possible to get files attachment on the record is send through email alert as attachment ? Here is what I found to send email with attachment but it does not show how to get the file from the record. http://anuragsfdc.blogspot.com/2014/02/send-email-with-attachment-from-apex.html

And I have create a method that can get the File on the record but I'm not sure how the attachment object and document object can be related with each other.

public static List<ContentDocument> getFilesDB(String recordId){ 
    try{
        Set<Id> recordIds = new Set<Id>{recordId};
            List<ContentDocumentLink> cdlList = [SELECT Id, LinkedEntityId, ContentDocumentId FROM 
                                                 ContentDocumentLink WHERE LinkedEntityId =:recordIds
                                                ];       
        
        Set<String> contentDocumentIds = new Set<String>();   
        
        for(ContentDocumentLink cdl:cdlList){ 
            if (!contentDocumentIds.contains(cdl.ContentDocumentId)){
                contentDocumentIds.add(cdl.ContentDocumentId);
            }               
        }  
        
        return [SELECT Id, Title, FileType ,FileExtension, ContentSize FROM ContentDocument WHERE Id IN :contentDocumentIds];  
    }catch(Exception e){
        System.debug('Executive_Ctrl -> getFilesDB: ' + e.getMessage() + ' at line ' + e.getStackTraceString());
        throw new NullPointerException();
    }
    
    
} 

I have try to find the workaround to convert from Content document to Attachment https://developer.salesforce.com/forums/?id=906F0000000AXYSIA4

But there is no solution yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.