You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 10, 2024. It is now read-only.
Current code fails to take into account VF hosts such as na1.salesforce.com:
// location.hostname is of the form 'abc.na1.visual.force.com', so we
// can simply split it on '.' and take the second element of the
// resulting array
this.instance_url = "https://" + location.hostname.split(".")[1]
+ ".salesforce.com";
As a result, it erroneously builds an instanceUrl such as salesforce.salesforce.com. Since there is no way to directly get the instance component or the whole URL in Visualforce, an acceptable heuristic would be to look at the number of elements in the hostname and choose the first or second as appropriate:
// location.hostname can be of the form 'abc.na1.visual.force.com' or
// 'na1.salesforce.com'. Split on '.', and take the [1] or [0] element
// as appropriate
var elements = location.hostname.split(".");
var instance = (elements.length == 3) ? elements[0] : elements[1];
this.instance_url = "https://"+instance+".salesforce.com";