function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NickNick 

Need to derive URL for /secur/frontdoor

I want to derive a general purpose JavaScript script that uses for example the URL for /secur/frontdoor.jsp, but I don't want to assume that it will aways start with https://na1.salesforce.com.

Can I safely assume that all of the URLs available via scontrol merge fields (Scontrol_URL, API_Enterprise_Server_URL_25, API_Enterprise_Server_URL_30, Scontrol_JavaCodebase, and Scontrol_JavaArchive) will always start with the same base for any customer session? If not, which one will be the right one to use for this purpose?

My preference is to use Scontrol_URL, extract it's base URL, and then assume that this is good enough to build up URLs for /secur/frontdoor, /servlet/servlet.SoapApi, and also to redirect the user to an object page (such as by appending Opportunity_ID to the base URL).

Nick

DevAngelDevAngel

Hi Nick,

Any url you decide to use is fine.  The context is the user.  Assuming the user is logged in, all the urls will point to the correct host for the user.  You could even derive the host from the location property of the hosting page (document.parent.parent.document.location or some such).

HaroldHHaroldH
Here's a snippet I use to derive the host Url from the API Url:

string apiUrl = sforceService.Url;
return apiUrl.Substring(0, apiUrl.IndexOf("/services")).Replace("-api","");
NickNick

Harold,

Thanks for the suggestion, but I've lost you. In your example

string apiUrl = sforceService.Url;

where does the sforceService object come from?

Thanks,

Nick

DevAngelDevAngel

Hi Nick,

the sforceService object is the "binding" object in the samples.  It is the main object that all the methods hang off of.  In the case of .Net it is a class and has a url property.  In java this would be the SoapBindingStub object.

Michael SMichael S

For a customer in Japan, this algorithm incorrectly returns

https://ap0.salesforce.com/0051.....

where it should return

https://ap.salesforce.com/0051.....

Is there an algorithm that will work worldwide?

Michael S. Scherotter

Here's a snippet I use to derive the host Url from the API Url:

string apiUrl = sforceService.Url;
return apiUrl.Substring(0, apiUrl.IndexOf("/services")).Replace("-api","");

DevAngelDevAngel

Hi Michael S.,

The recommended method to determine the url is to use the describe call which contains 3 urls "templates" for displaying various views on an object.  The views supported are detail, edit and new.  This means that we provide a url for viewing the object, going directly to an edit screen or directly to a "new" object screen.

This property is not available on every object, but only for the "main" objects such as Account, Contact, etc.  The format, and this is the part that relates to the post, is:

https://[server_instance]/{mergeField}

Where [server_instance] is what you are trying to obtain with the algorithm from the post.  The {mergeField} is the name of a field on the object being described, that you would replace with an actual value.  So for my developer edition and account detail link from the describe would look like:

https://na1.salesforce.com/{ID}

And with the value:

https://na1.salesforce.com/001300000043mRjAAI

Now, you can run the describe on the account object and parse out the merge field to obtain the base url for any frontdoor.jsp link you want to construct.

Cheers

Michael SMichael S

The detailURL field is not complete because the following objects do not have any value for detailURL even though I can make one up myself by appending the /ID onto the server URL:

Asset, Contract, Note, Partner, CaseHistory, CaseComment

Michael

Michael SMichael S

So we should not make URLs to objects that do not have detailURL values?

Please explain the logic that we should follow to get the detailURL of any object.  

Michael

darozdaroz

I documented these, and some others, in case 358012...

Asset, Attachment, BusinessHours (mabye), Contract, MailmergeTemplate, Note, OpportunityLineItem, Pricebook2, Product2, SControl, User, UserRole, and WebLink all do not have URLs devines in the describeSObject return. If I recall I did test the https://[server].salesforce.com/ID url schema with each of these and get get at least the view page back for each... you'll have to test yourself to try the create/edit syntax.

I already coded around this problem so that case has been a relatively low priority for me to followup on.

Hope that helps.

Michael SMichael S

What algorithm do you use to determine the [server]?

This does not work in Japan:

string apiUrl = sforceService.Url;
return apiUrl.Substring(0, apiUrl.IndexOf("/services")).Replace("-api","");

Michael

DevAngelDevAngel
Michael,

To determine the server, use the url from the describe of an Account.