1

I have a question regarding this post: handle PDF content in HTTP callout

When I try the above code I'm getting this:

"Unrecognized base64 character: %"

The logs show this as well:

19:53:04:658 VARIABLE_ASSIGNMENT [285]|base64Response|"%PDF-1.3\r\n%����\r\n3 0 (82794 more) ..."

Any ideas?

Thanks!

  • That's not a base-64 string, it's the actual binary PDF data. – sfdcfox Nov 13 at 15:26
0

You are getting a blob directly. Why not save the blob directly using resp.getBodyAsBlob()

String endPoint ='http://resources.docs.salesforce.com/rel1/doc/en-us/static/pdf/salesforce_query_search_optimization_developer_cheatsheet.pdf';


HTTP h = new HTTP();
HTTPRequest request = new HTTPRequest();
request.setEndpoint(endPoint);
request.setHeader('contentType', 'application/json');
request.setMethod('GET');
HTTPResponse resp = h.send(request);
if(resp.getStatusCode()==200){

    Attachment attach = new Attachment();
    attach.contentType = 'application/octet-stream';
    attach.name = 'myfile111.pdf';
    attach.parentId = '0010C000006ReQW';
    attach.body = resp.getBodyAsBlob();
    insert attach;
}

In my code, I am downloading a SF document PDF and saving it as an attachment on an account record

  • That did the trick! Thanks so much! – George Nov 15 at 4:42
  • @George can you accept answer? It will help someone with similar querry reach solution faster – Pranay Jaiswal Nov 15 at 6:05

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.