I need to send email along with attachments which reside in a different platform to external email IDs. below is the code snippet which I have done so far. Please suggest how to proceed further.

Rest Class

Global class GETPDFContent{
global static void sendEmail(String EmailIdCSV, String Subject, String body) 

List<String> EmailIds = EmailIdCSV.split(',');

    PageReference ref = Page.PDF_DEMO;
    ref.getParameters().put('id', '00590000000ZiGV');
    //Id is User ID
    Blob b = ref.getContentAsPDF();

    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

    Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();

    String addresses;
    email.setSubject( Subject +String.valueOf(DateTime.now()));
    email.setToAddresses( EmailIds  );
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
    Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});




 public with sharing class PDFController {

 public User u{get;set;}
 public Account Acc{get;set;}
 public Id accountId{get;set;}

 public PDFController(ApexPages.StandardController stdController){
 accountId = apexpages.currentpage().getparameters().get('id');
 //Acc =[Select id, Name,Phone FROM Account];
 u = [Select id,AccountId,Name, Account.Name,Account.phone from User where 
 id=:accountId limit 1];
 acc = [Select Id, Name,Phone From Account Where Id =: u.AccountId];


 // Pass in the endpoint to be used using the string url
 public String getCalloutResponseContents(String url) {

// Instantiate a new http object
Http h = new Http();

 // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();

// Send the request, and return a response
HttpResponse res = h.send(req);
return res.getBody();


VF Page:

<apex:page showHeader="false" standardController="User" 
extensions="PDFController"  sidebar="false" renderAs="pdf" 
applyBodyTag="false" docType="html-5.0" >
    <style type="text/css">
        body {
            font-family: 'Arial Unicode MS';

           @page {
            size: letter;
            margin: 20mm;      

 <apex:outputText style="font-size: 13px;background-color: yellow;" value="
 {0,date,MMMM dd, yyyy}">
  <apex:param value="{!TODAY()}" />

  • What are you having trouble with ? Aug 31, 2017 at 7:51

1 Answer 1

  1. Figure out a way to read the attachment data from the "different platform". Typically you will need to first authenticate and then make HTTP or HTTPS requests to get the data. Apex includes the building blocks you need for this but the details depend on exactly what the "different platform" offers.
  2. Use the Apex Messaging.SingleEmailMessageand Messaging.EmailFileAttachment classes to send the email addresses. There is an example of that sort of code in the Creating an Email Attachment documentation.
  • @SalesforceLearner The data being public makes it much easier. I've added a link to the Apex HTTP classes you can use to request the data.
    – Keith C
    Aug 30, 2017 at 8:05
  • I've updated my question with the code which I have tried. Not sure how to proceed further to send the mails. Please suggest. Aug 31, 2017 at 5:40
  • @SalesforceLearner The links in my answer provide examples: you'll hardly ever find exactly the code you need. Instead you need to experiment and fix compile errors and runtime errors (use the debug log) until you figure it out.
    – Keith C
    Aug 31, 2017 at 7:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .