Get the Salesforce Internal (non-Site) URL from a Site

(This is the opposite question of Get Site URL from apex.)

I’m running Apex in a request on a Site page. URL.getSalesforceBaseUrl().toExternalForm() gives me

I want my actual instance URL: or even How can I get it?


I recently faced this exact scenario and also found an answer to this. Use this code snippet to get salesforce instance url when working on a site page


Per the documentation:

X-Salesforce-Forwarded-To : The fully qualified domain name of the Salesforce instance that is handling this request. This header is always set on HTTP and HTTPS requests that are initiated outside of Salesforce’s data centers.

Related PageReference headers documentation

Source : Link , Question Author : Benj , Answer Author : Mark Pond

Leave a Comment