You need to sign in to do that
Don't have an account?
canonw
Determine SalesForce instance or URL in code
Hi everyone.
Is there a Apex class method to get current Salesforce.com instance or URL at runtime?
I want to generate hyperlinks like https://na4.salesforce.com/{accountId} in code. But I don't want to hard code 'na4'.
Every time I deploy the same code back to Sandbox, I must fix the instance manually.
Thanks in advance.
Is there a Apex class method to get current Salesforce.com instance or URL at runtime?
I want to generate hyperlinks like https://na4.salesforce.com/{accountId} in code. But I don't want to hard code 'na4'.
Every time I deploy the same code back to Sandbox, I must fix the instance manually.
Thanks in advance.
I'm curious if 'na1' construct is a wild card to replace the instance in sandbox too (e.g. cs1 instance).
Is there a document about na1 construct?
To tell you the truth I just tried it with some expectation that it was going to break and some hope that thier system would just auto correct.
The short answer is that it works, and I hope it's a feature and not a bug that they will later fix. LOL!
We have the same problem. Rt now we are checking for the org id and if it is production, we use na5, if not we use tapp0. But even this has a problem. Sandbox's instance may change after a refresh. This would be a problem in HTML email templates also.I hope there will be some function(s) to retrieve the current orgs's url.
The folowing idea might work too. User's session id contains details of the instance. The letter after "00D" determines the instance. If it is "T" then the instance is tapp0.
T - tapp0
S - cs1
R - cs2
Q - cs3
P - cs4 and so on
Where are you putting the url?
In visualforce, if you use an apex:outputlink you can set the value = "/{!ID}" or "/apex/..." and the output control takes care of it for you. Works on Page Redirects in APEX too.
Frick'n Emoticons! LOL! Always gets me.
should be like <apex: outputlink>
hope that worked.
Here is the unit test
You could use the above to return NA4 / CS2 as necessary.
This works!!
URL.getSalesforceBaseUrl().toExternalForm();
We're using URL.getSalesforceBaseURL().toExternalForm(), but it's returning http://xxxx.force.com/ since the code is being called from a Sites page. =[