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
Carl HCarl H 

How to get salesforce Host name from Apex Class

Hi all,

I'd like to get salesforce URL (https://na2.salesforce.com) inside Apex class, may i know what is the syntax.
i tried the "ApexPages.currentPage().getParameters()" but it only return me the parameters at behind, how to get the host name?
werewolfwerewolf
Try pulling it out of ApexPages.currentPage().getUrl() instead.
Carl HCarl H
Hi,

the ApexPages.currentPage().getUrl() only return the short URL, exmaple /apex/myVFPage.
and not full URL like http://na2.salesforce.com.....

werewolfwerewolf
Did you try getting it out of the headers?  The domain's got to be in there somewhere...
jlojlo

ApexPages.currentPage().getHeaders().get('Host') should do the trick.