7

I have some customer orgs that still work on Classic and didn't enable MyDomain. This causes strange errors. Is there a way I can check with Apex if an org has a MyDomain enabled?

1

2 Answers 2

6

I would just check:

Boolean isMyDomainEnabled = URL.getSalesforceBaseUrl().getHost().endsWith('my.salesforce.com');

Or maybe:

Boolean isMyDomainEnabled = URL.getSalesforceBaseUrl().getHost().contains('--');

That should return true for all orgs with MyDomain enabled, as the url format there would be domain--sandbox.cs42.my.salesforce.com. In orgs without, it would just be cs42.salesforce.com.

2
  • I have orgs without "my" in their mydomain. Commented Feb 19, 2018 at 15:20
  • 1
    What about checking .contains('--')?
    – Adrian Larson
    Commented Feb 19, 2018 at 15:22
4

Try URL.getSalesforceBaseUrl().getHost();. In some cases you might also get useful info out of a query such as [SELECT fullPhotoUrl FROM User WHERE userType = 'Standard' LIMIT 1].

Credit to Cristophe Coenrats for both. His repo here https://github.com/ccoenraets/lightning-component-apex-continuation contains code that allows Apex continuations in Lightning, and as a result his Visualforce and Lightning components need to successfully guess each other's base URLs in order to communicate successfully.

0

You must log in to answer this question.

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