I'm trying to get the public site's url (ending part of it), to control show/hide some controls according to the location apex page being called.

I tried using below.


But it doesn't show the public URL set in force.com sites, but showing apex/Pagename instead.

Can we get the public force.com site url within controller class. Any help would be great. Thanks.


For a Salesforce Site, use the Site class. Namely, you can use Site.getBaseRequestUrl() to determine the current URL of the request.

Returns the base URL of the current site for the requested URL. This isn't influenced by the referring page's URL. The returned URL uses the same protocol (HTTP or HTTPS) as the current request. The returned value includes the path prefix and never ends with a / character. If the current request is not a site request, then this method returns an empty string.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.