I am looking for ways to find out whether salesforce org is enabled with enhanced domains or not via apex.

As per this document, the content (files) domain is different in each case. And dynamically finding out whether enhanced domains are enabled or not, will help to construct the absolute path of the salesforce file via apex.

I am trying to construct URL <contentBaseURL>/sfc/servlet.shepherd/version/Download. We can use URL.getOrgDomainUrl() for contentBaseURL but salesforce internally does redirects to one of the following URLs based of enhanced domain enabled or not.

//with enhanced domain redirects to 
Content(files): MyDomainName.file.force.com

//without enhanced domain redirects to 
Content(files): MyDomainName--c.documentforce.com

1 Answer 1


You can use the DomainCreator class for this. It will return the correct URL in both cases:

  • 1
    This is exactly the solution I was looking for, thanks. Jun 15, 2022 at 9:41

Not the answer you're looking for? Browse other questions tagged .