I am using forcetk to upload files (as Attachment records) in a VisualForce Page and it works fine. But when I access same page in a Community, I am not able to upload the file as I am getting the "503 Service Unavailable" in console. Is this proxy is accessible in communities?

  • Hi guys, with little bit of search came to know that request url has to be set in forcetk.Client(). So I used the clientId as null, loginUrl as login url for Community and proxyUrl as "services/proxy". When i tried with this request url is becoming -> "loginUrl/apex/services/proxy" instead of "loginUrl/services/proxy". Could you please let e know is there any way i can change this? Thanks Commented Sep 23, 2014 at 10:36
  • Was able to form the link but every time i am getting the "[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]" error. Please suggest. Commented Sep 23, 2014 at 13:44
  • I have the same problem when using AngularForce, which is a glue b/w AngularJS and ForceTK.
    – Oscar Tang
    Commented Nov 4, 2014 at 8:06
  • @ShrivathsKulkarni did you find a way around this? I'm currently faceing the same situation Commented Oct 20, 2015 at 16:10

3 Answers 3


You can retrieve the URL of the Community reliably using the following Apex (and return it to the client using @AuraEnabled or @RemoteAction):


Then append the proxy/service endpoint to use in ForceTK or an XHR as your normally would


I have a solution for this if you are willing to edit your copy of forcetk.js https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/forcetk.js

find function: forcetk.Client.prototype.setSessionToken leave it as is but at the end add:

this.instanceUrl = 'your community url';
this.proxyUrl = null;
this.visualforce = false;

This is a hack, there are ways to clean this up better, but this is the least intrusive modification I could pull off quickly.

I originally was using jsforce (which handles this nicely). Unfortunately, jsforce currently doesn't support IE9 so that's why I am here :)

  • 1
    This did not work for me. Does some other resolve this issue? Commented Oct 20, 2015 at 8:24
  • 1
    This should work @jonathanwiesel make sure you include the site prefix if you have one at the end of the instanceUrl: domain/site-prefix Commented Oct 29, 2015 at 4:01

If you want the same Visualforce page to work in both a Community and outside a community, you need to construct the correct instance URL and proxy URL:

var elements = location.hostname.split(".");
var instance = (elements.length == 3) ? elements[0] : elements[1];
// Are we on a Community page?
var baseURL = '{!$Site.BaseUrl}' || null;
var proxy = '/services/proxy';
var instanceURL =  baseURL || ('https://' + instance + '.salesforce.com');
var proxyURL = baseURL ? (baseURL + proxy) : proxy;

var client = new forcetk.Client();
client.setSessionToken('{!$Api.Session_ID}', 'v35.0', instanceURL);
client.proxyUrl = proxyURL;

You must log in to answer this question.

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