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
tony2009tony2009 

How to get the site url from Apex Code

Hi Guys,

Is thera any way I can got the site url from Apex Code?

I tried Site.getPrefix() , Site.getDomain() and getCurrentSiteUrl. but all of them return null.

Do I need setup some information after the site is ready.

Thanks in advance.

LakshmanLakshman

Please give a try using URL methods. More details for all URL methods can be found here-> http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm 

 

Regards,

Lakshman

Tejpal KumawatTejpal Kumawat

Hi try to this it will be definately works...

 

public String getSiteUrl(){
return Url.getSalesforceBaseUrl().toExternalForm();
}

tony2009tony2009

Thanks guys,

 

from Url.getSalesforceBaseUrl().toExternalForm(), the result like https://na12-api.salesforce.com. which is salesforce internal domain.

 

Is it possible to get the salesforce.com site domain name something like http://XXX.force.com ?

 

 

tony2009tony2009

What I am doing is to make the attachments public via force.com site,  the url pattern for attachment is {!$Site.Prefix}/servlet/servlet.FileDownload?file={!List.Image},

 

Unfortunately, I have to expose those the attachment image via web service. so I have to get the site domain from Apex Code.

 

Or Is there any way to expose images directly?

 

Thanks


DhuravDhurav

Hey tony, if you use Site.getCurrentSiteUrl it will be provide the url of site...If it is not provide then change the public settings in the site settings... then also check

tony2009tony2009

Thanks Dhurav,

 

I still got null using  Site.getCurrentSiteUrl.

 

I couldn't find any settings for this url from public settings.

 

Can you point our what inforamtion I need to setup in public settings ?

 

Thanks a lot