3

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
4

Apex controller is enough to do this:

// Sample code only 

HttpRequest req = new HttpRequest();
// set endpoint destination
req.setEndpoint( 'http://mydestination.com');
req.setMethod('POST');
req.setHeader('Authorization', 'OAuth ' + access);
req.setHeader('Content-Type','application/json');
// 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
req.setBody(base64PDF);
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

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.