Skip to content

Commit 785dc35

Browse files
author
metadaddy
committed
Look at structure of VF hostname and choose first or second element for instance as appropriate. Closes developerforce#4.
1 parent 7e9a13d commit 785dc35

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

forcetk.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ if (forcetk.Client === undefined) {
5353
this.sessionId = sessionId;
5454
this.proxy_url = location.protocol + "//" + location.hostname
5555
+ "/services/proxy";
56-
// location.hostname is of the form 'abc.na1.visual.force.com', so we
57-
// can simply split it on '.' and take the second element of the
58-
// resulting array
59-
this.instance_url = "https://" + location.hostname.split(".")[1]
60-
+ ".salesforce.com";
56+
// location.hostname can be of the form 'abc.na1.visual.force.com' or
57+
// 'na1.salesforce.com'. Split on '.', and take the [1] or [0] element
58+
// as appropriate
59+
var elements = location.hostname.split(".");
60+
var instance = (elements.length == 3) ? elements[0] : elements[1];
61+
this.instance_url = "https://"+instance+".salesforce.com";
6162
this.apiVersion = (typeof apiVersion === 'undefined' || apiVersion == null)
6263
? 'v21.0' : apiVersion;
6364
}

0 commit comments

Comments
 (0)