+ Start a Discussion
Shubham SonarShubham Sonar 

retrive a force.com site domain

I am trying to fetching my force.com site domain I have created. Gone through lot of internet contents but find no where a solution to fetch the complete Domain/Default site url. Possible is to query urlPathPrefix and salesforce.com domain, but not the complete force.com domain I have created.

for example: ***-developer-edition.ap2.force.com
                   ***-developer-edition.na3.force.com
                   ***-developer-edition.XYZ.force.com

could be fetched properly!
Best Answer chosen by Shubham Sonar
Amit Singh 1Amit Singh 1
Hi Subham,

Use the below SOQL Query for getting the force.com site domain.
SELECT Id,MasterLabel,Name,Status,Subdomain,UrlPathPrefix FROM Site
force.com domain.

Use below SOQL Query for getting the org instance Id/Name.
SELECT InstanceName FROM Organization
Organization Instance Name

Let me know if this helps for you :)

Thanks,
Amit Singh.
 

All Answers

Manu MohananManu Mohanan
HI,

This answer may help you.

http://salesforce.stackexchange.com/questions/14532/get-visualforce-url-with-custom-domains-turned-on

 
Shubham SonarShubham Sonar
hey manu, actually i have gone through this code, which returns me my salesforce.com url. Where as i want to fetch my force.com site domain url, which i have deployed. anyways thanks for repsonding and do let me know if you get some more inputs on this. 
Shubham SonarShubham Sonar
as well as i need the org instance id viz: na3, ap2, etc. in it so.
Amit Singh 1Amit Singh 1
Hi Subham,

Use the below SOQL Query for getting the force.com site domain.
SELECT Id,MasterLabel,Name,Status,Subdomain,UrlPathPrefix FROM Site
force.com domain.

Use below SOQL Query for getting the org instance Id/Name.
SELECT InstanceName FROM Organization
Organization Instance Name

Let me know if this helps for you :)

Thanks,
Amit Singh.
 
This was selected as the best answer
dsksatishdsksatish
Hi,
Not sure if this issue is resolved for you. Apart from Amit's reply above, we also have a getDomain() method in the Site Class. Or you can use the getBaseUrl() method in the same Site class and parse it.

More Information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_sites.htm

Thanks,
Satish Kumar

Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Ken Koellner 1Ken Koellner 1
I'm trying to find a way to get the configured Sites domain, not from the context of a configured site.  I'd like to from internal objects compute the URL of a page on a configured Site.  I beleive the Site class only works in the context of code run from a Site itself.
Ken Koellner 7Ken Koellner 7
Any result on this?  It like to get the configured Sites domain from the org in Apex in order to do some initialization script but I haven't found a way to get it.
kailash chandra 22kailash chandra 22
No need to get Url Prefix through SOQL Query
Site Class will provide you
System.debug(Site.getPathPrefix());
Ken Koellner 7Ken Koellner 7
The Site.getPathPrefix() will not work for my use case as it is code running outside the site that must get the URL path.  There is code running while logged in the calculates URLs to various places in the site including several parameters and stores them in objects.  To make it easy, we just put the root URL in a custom setting field.  It would be more elegant to calculate it.  We would have to use a technique like further above where we query the Site object and Organization object and the construct the root URL from pieces.