Skip to main content

I want to attach FILE to email attachment using apex, but after sending mail that related file attachment get corrupted , what is the actual problem? following is my code--

 

 List<ContentDocumentLink> ContentDocumentLinks=[SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :Id];

            Id docid=ContentDocumentLinks.get(0).ContentDocumentId ;

            system.debug('docid'+docid);

            List<ContentVersion> ContentVersions=[SELECT Id,Title,VersionData FROM ContentVersion WHERE ContentDocumentId  =:docid AND Description = 'Survey Invoice PDF'];

            if (ContentVersions.size() > 0)

            {

                pdfBlob = ContentVersions.get(0).VersionData;

                fileName = ContentVersions.get(0).Title;

                existingRecord = true;

                system.debug('pdfBlob....'+pdfBlob);

                system.debug('fileName...'+fileName);

            } 

0/9000