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
MPondMPond 

Get Secure Web Address programmatically?

Is there a method to get a Site's 'Secure Web Address' programmatically? Maybe via an undocumented method call?

 

I want to avoid using a Custom Setting entry to store a system generated value which is already defined by the system out of the box and I also don't want logic in code to programmatically build a URI in a controller.

 

Looking for the secure equivalent of Site.getDomain()

 

Thanks in advance!

Mark

Best Answer chosen by Admin (Salesforce Developers) 
Alok_NagarroAlok_Nagarro

Hi,

 

There is no any standard method to access Site's 'Secure Web Address'. You need to construct it programatically in controller.

 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet to get the URL:

URL.getSalesforceBaseUrl().toExternalForm();

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

Alok_NagarroAlok_Nagarro

Hi,

 

There is no any standard method to access Site's 'Secure Web Address'. You need to construct it programatically in controller.

 

 

This was selected as the best answer
MPondMPond

Thank you for the confirmation. 

 

For anyone coming along later, some context and how I got here:

In a sandbox org the Site force.com domain is the same for both secure and not

however, in a production org this is not the same pattern.

This data needs to be based on the org context and it would be REALLY nice to simply make a system method call that will return this information, which should be trivial considering it's already provided on the Site detail page.

 

For the sake of time, I implemented this as a custom setting value which stores the 'Secure Web Address' domain value for the org. The value is read by the page controller and a secure URL is returned by a controller method call.

 

Thank you for your help!

Mark