I'm trying to upload an image file to Facebook from Salesforce and current this is my codes and it is not working can anyone help me fix it?

Please Note that my Image file is inside the Accounts Notes & Attachments

I tested the string that I use for salesforcephoto and it Uploaded something onto Facebook using the Facebook Graph API explorer Uploaded using Facebook Graph API Explorer

Save Session for the Facebook Graph API Explorer Click Here

The String I use for salesforcephoto

String salesforcephoto = 'https://c.ap4.content.force.com/servlet/servlet.ImageServer?file='+lstRelatedAttach[0].Id+'&oid=' + orgid ;

The Codes are Codes

Debug Log Errors

Debug Log Errors

Redirecting to login page

Currently this my link I'm using for my testing and it will redirect me to the login page instead of showing the image.


I have tested this other link but it will give me an error message


enter image description here

  • 1
    Please explain what you are trying to do?
    – Saroj Bera
    Mar 31, 2017 at 9:46
  • I'm trying to upload a photo onto Facebook from Salesforce using the photo's URL that is from Salesforce
    – Luke Au
    Mar 31, 2017 at 9:48

2 Answers 2


I need to add the file to the a document folder before I can access the url at other locations


The first thing that stands out to me is that you have that url for the salesforce document added directly as a query string parameter, when you should url encode it first:

...'/Photos?url=' + EncodingUtil.urlEncode(salesforcephoto, 'UTF-8');

Also the format of the salesforce document url should be something like:


Where <id> is the id of the document, and <oid> is the id of you org. I believe the lastMod param is optional.

That other url with the resource at /servlet/servlet.FileDownload?file= is for the same image, but requires login.

  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Adrian Larson
    Mar 31, 2017 at 14:27

You must log in to answer this question.

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