How do I send a pdf through REST call out of Salesforce? Should we use sites? Any idea?

  • 1
    You can make RESTful HTTP calls out from Apex code via the HttpRequest class. So as long as you are initiating the request e.g. from a controller you do not need things like Force.com Sites. – Keith C Sep 24 '14 at 9:56

Apex controller is enough to do this:

// Sample code only 

HttpRequest req = new HttpRequest();
// set endpoint destination
req.setEndpoint( 'http://mydestination.com');
req.setHeader('Authorization', 'OAuth ' + access);
// get the PDf. Can be other ways
Blob pdfBody = Page.SamplePage.getContentAsPDF();
// convert to base64 string
String base64PDF = EncodingUtil.base64Encode(pdfBody);
// Set PDF body here
Http http = new Http();
// send the request
HttpResponse response = http.send(req);

For more detail: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httprequest.htm

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.