I've prepared a managed package that includes Lightning components, and the main one belongs to the FlexiPage that is shown when you open the application. I've installed it to a different org, but when the tab is open I just see an error message. Like this

enter image description here

I found it that this is because My Domain feature was not enabled in this org so I wonder: is there any way for me to check whether this feature is enabled and run this check before the package is installed or when the application is first run?


You could possibly use the following SOQL query to retrieve the Domain object details available in Salesforce.

[SELECT Id, CnameTarget, Domain, DomainType, OptionsExternalHttps FROM Domain]

This could be done on the onInstall() method of the System.InstallHandler interface provided within Apex to trigger activities on Managed Package installation and uninstallation.

global class PostInstallClass implements InstallHandler {

  global void onInstall(InstallContext context) {
    List<Domain> availableDomainList = [SELECT Id, CnameTarget, Domain, DomainType, OptionsExternalHttps FROM Domain]);

    //If Domains do not exist on the target org
    if(availableDomainList == null){

       //Throw Custom Exception to halt installation


Refer the Apex Developer Guide to understand more about how the InstallHandler Interface can be leveraged.

  • Well, thanks for the InstallHandler. However it seems that this SOQL doesn't help, as it returned 0 record for both org with My Domain and another org without it
    – Demarsch
    Jun 22 '18 at 2:47
  • Have you tried querying the Organization object. Something like [Select Instancename from Organization].
    – Jigar Shah
    Jun 22 '18 at 3:08
  • 1
    I found this way to check though it seems a bit clumsy salesforce.stackexchange.com/questions/208660/…
    – Demarsch
    Jun 22 '18 at 3:40
  • That's a good hack to know!
    – Jigar Shah
    Jun 22 '18 at 7:36
  • Doesn't this object store more records than just My Domain?
    – Adrian Larson
    Jun 22 '18 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.