Get Site URL from apex

Is there a way to get the URL of a salesforce site from apex

I need this to send the url in an email message, so the apex is run outside of the site context. I basically want to expose a link to my salesforce site in an email message. But so far I haven’t found a way to do that

I would prefer not hard coding the url in apex


Since Winter ’17 (v38.0)

You can get the secureURL using the SiteDetail object

Site mySite = [select Id from Site where Name = 'MySite'];
SiteDetail mySiteDetail = [select SecureURL from SiteDetail where DurableId = :mySite.Id];

Source : Link , Question Author : pjcarly , Answer Author : Community

Leave a Comment