0
 public static String AcceptTnC(String contractInfo2){

    system.debug('contractId2'+contractInfo2);

    Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
    Messaging.EmailFileAttachment attachmentPdf = new Messaging.EmailFileAttachment();
    String strObjType = String.valueOf(contractInfo2);
    strObjType=strObjType.replaceAll('</span>','');
    strObjType=strObjType.replaceAll('<span[^>]*>','');
    strObjType=strObjType.replaceAll('<br>','\n');
    strObjType=strObjType.replaceAll('<b>','');
    strObjType=strObjType.replaceAll('</b>','');
    strObjType=strObjType.replaceAll('<*>','');
    strObjType=strObjType.replace('&nbsp;',' ');
    system.debug(' strObjType:'+ strObjType);
    //  Blob b=blob.valueOf(strObjType);

    attachmentPdf.setContentType('application/pdf');
    attachmentPdf.setFileName('Partner Program agreement.pdf');
    blob Agree_blob=blob.toPDF(strObjType);
    system.debug('Blob value:'+Agree_blob.toString());
    attachmentPdf.setBody(Agree_blob);
    //system.debug(attachmentPdf);
    /*doc.Name='Partner Program agreement';
    doc.ContentType='text/plain';
    doc.body=blob.valueOf(strObjType);
    doc.Type = 'doc';
    system.debug('doc id'+doc.id);
    insert doc;*/

    //  semail.setEntityAttachments(doc);*/
    semail.setPlainTextBody('hi this is pdf type email at 13th may');
    semail.setSubject('Partner Program agreement');
    String[] sendTo = new String[]{'xyz@gmail.com'};
    semail.setToAddresses(sendTo);
    system.debug('address set'+sendTo);


    semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attachmentPdf});
    system.debug('reached to set File attachments..');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});  
    system.debug('mail sent to '+sendTo);
    return null;


}
  • Please take a moment to go through how to ask and then edit your question to provide necessary details including any errors that you may be receiving. In its current form the question lacks the details for anyone to be able to help you. – Vijay Ganji May 14 '19 at 9:03
  • it is not clear for me what is your issue.... – m Peixoto May 14 '19 at 9:17
  • I am using apex to send email with pdf attachment, but the content in the pdf file is getting trimmed. the actual data (i.e data in ContractInfo2 ) is of size 21.1 KB but I am receiving only 2.1 KB of file in email. – sandhya panchal May 14 '19 at 10:26
  • You can't compare byte sizes when you're running a number of replaceAll() regexes on the content before sending. The result should not be expected to be the same size. – David Reed May 14 '19 at 11:29
  • Thank you for your reply,but the thing is actual content is also getting trimmed. becoz i have first replaced all the html tags and then through strObjType i am converting it into pdf,hence data from strObjType should not get trimmed and should be sent as it is,which is not happening in my case. – sandhya panchal May 15 '19 at 4:02

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.