+ Start a Discussion

How to obtain the Force.com Sites domain (docs are wrong?)

Hello. I have a Force.com Site domain configured, and a Force.com site. The Force.com Site domain shows under Domains > My Domains. I can query the Site object, and it has the proper SubDomain value.

According to the docs, I should be able to query the Domain object and find this Force.com Sites domain. Also, there should be a DomainSite record linking the Site to the Domain. Right?

I query both the Domain and DomainSite objects (as a System Administrator), and both queries return no results.

I want to check, from Apex code (or using the Metadata API or something) whether there's a Force.com Sites domain set already on the org, and it's sub-domain component. Even when there are no sites created (I guess in that case I could query for a Site record with Type = Force.com Site, and use the SubDomain value?).

The final objective here, is being able to programatically create a Force.com Site. We intend to use the Metadata API for doing this.

Any ideas? Thanks!

SandhyaSandhya (Salesforce Developers) 
Hi agrassi,

Not sure why you are not getting,But still i would suggest you to consider below points from salesforce document.

Customer Portal users can’t access this object.
To view this object, you must have the “View Setup and Configuration” permission.
Site.com Publisher users have read-only API access to the Domain and DomainSite objects.


Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
Thanks and Regards

Hi Sandhya. Thanks for your reply. I did see those points. This is a standard System Administrator profile on an EE org, so should be OK..

Found lots of material regarding how to obtain the URL of a configured Site. But this isn't the case, what I want is to obtain the Force.com Sites configured domain (something that is done once and cannot be changed), in order to:
  • Programatically check if this has been done, and if not instruct the user in the right direction
  • Programatically create a Force.com site, but for this I need to pass a subDomain value? We are planning on using the Metadata API for this point.
Any ideas? Anyone?
Ken Koellner 1Ken Koellner 1
Trying to find the same thing, get the Sites domain from code not running in the context of a Sites controller code.  I haven't found a way to do it.  Querying Domain object from anonymous apex yielded zero rows. 
Ivaylo DimovIvaylo Dimov
Has anyone been able to find a solution for this. I am having the same issue trying to get the Domain.
Iris GaleanoIris Galeano
Has anyone been able to find a solution for this issue? I want to get also the site domain. I query both the Domain and DomainSite objects (as a System Administrator), and both queries return no results but if I go to Setup -> Domain -> The Force.com Site domain is listed there.
weno bakweno bak
Great feature Lots of the message to Read. Your use of formatting when making your points makes your observations very clear and easy to understand. Thank you for posting such a great article. If you like video games then visit the given link and know “StarCraft 2 Cheats for the Single-Player Mode (https://gtacheatcode.com/starcraft-2-cheats/)” and click here for “GTA 3 Cheats. Thanks and with luck I'll see you here shortly – Carl Johnson