You need to sign in to do that
Don't have an account?
Identifying what server the code is on (cs1, na3, eu0, etc)
I looked through the Apex documentation and I didn't see any methods that return the server the code is executing on. I figure it has to be there and I'm just missing it as this would be required for packaged apps so they scales across all servers.
What I am doing is build a string that is a hyperlink but I need the server instance (na3, cs1) so I can build out the correct link.
opp is a Opportunity object.
String link = 'https://na3.salesforce.com/'+ opp.id;
Hard coding the na3 is not a good solution. Maybe there is some other way to do this?
Perhaps:
String link = opp.getLink();
but I didn't see anything like this.
Thanks for the help.
-Jason
What I am doing is build a string that is a hyperlink but I need the server instance (na3, cs1) so I can build out the correct link.
opp is a Opportunity object.
String link = 'https://na3.salesforce.com/'+ opp.id;
Hard coding the na3 is not a good solution. Maybe there is some other way to do this?
Perhaps:
String link = opp.getLink();
but I didn't see anything like this.
Thanks for the help.
-Jason
http://ideas.salesforce.com/article/show/10091004/Apex_method_to_identify_salesforcecom_server
All Answers
This is definately not the most elegant solution to handle this, but it definately beats hard coding anything. I perform the call to Retrieve_URL_Prefix a couple of times in the test method so that I can confim multiple calls will only run the SOQL query one time.
Unless you're sending an email, it doesn't matter what server you are on. Just use a link like this:
oppLink = "/{!Opportunity.Id}"
The browser will automatically figure out what server you're on...
Totally agree. In our case, we were sending an email, which is why I had to resort to the above.
Jon Keener
jhkeener@ashland.com
I am familiar with that method but it does not work in my scenario. What I am doing is building the body of an Activity and in this text there are hyperlinks to related records in salesforce.com. Therefore I need to code the entire URL.
Even Jon's method requires "hardcoding" the value. Not in code but still in a custom object. For packaged apps this won't scale well. A system method is really required for this.
I definately didn't like to hard code it, even in a custom object, but it was the only solution I could find.
From a packaging perspective, you could include an s-control to create the record in the table. From an s-control previously, I was able to substring the API URL to get to the Salesforce Instance I was on.
Below is a snippet of javascript code from an s-control. Doesn't do anywhere near what it would need to do in this instance, but you should get the idea. Assuming you were packaging this up, it would just be a requirement that the s-control was ran immediately after installation of the package to a new environment.
I definately think a function needs to be added to APEX to obtain this information, and once something is added, I plan to switch to it. But for now, I'm not sure if there is a better option than what's here.....
Jon Keener
jhkeener@ashland.com
then first time user clicks on this link in email, user will be prompted to login and force.com will figure out the instance and redirect the user appropriately. Subsequent clicks will directly take the user to correct object as long as there is a valid session.
It may not work for sandboxes!
http://ideas.salesforce.com/article/show/10091004/Apex_method_to_identify_salesforcecom_server
Execute EZSAAS wrote:
Jason - if you prepare your link as this: https://login.salesforce.com/?startURL=OBJECT.Id
then first time user clicks on this link in email, user will be prompted to login and force.com will figure out the instance and redirect the user appropriately. Subsequent clicks will directly take the user to correct object as long as there is a valid session.
It may not work for sandboxes!
Thanks for the tip - this is exactly what I need to do.
However, I'm being redirected to https://na2.salesforce.com/secur/006ABCDEC... and getting an error (for first and subsequent clicks.) If I remove /secur/ from my redirected url, all is well. Any ideas?
https://login.salesforce.com/?startURL=/OBJECT.Id redirects properly.
Unfortunately, now I'm being asked to log in each time. Subsequent visits do NOT recognize that I'm already authenticated. I've verified this behavior in both sandbox and production environments.
-Jason
i'll keep looking for a method to do this
ApexPages.getCurrentPage().getHeaders().get('Host'); works :) thanks XactiumBen
Message Edited by Scott.M on 09-26-2008 07:02 AM
string host = ApexPages.CurrentPage().getHeaders().get('Host');
Returns a null pointer exception. I guess this makes sense as this is a webservice and there isn't really a current page. I guess this is just more of a reason for there to be an apex method that returns this value.
I tried various attempts in a trigger with very little success.