2

Suppose I start with a package that has a custom VF page, and then down the road I want to build other packages that act as modules to that same VF page.

Is it possible to detect the existence of other packages and modify the VF page when they're installed?

I have a test app with three commandButtons, however only the first one is enabled in the core package. The plan is to have each of the other two commandButtons enable when its corresponding package is installed.

<apex:commandButton value="Go Platform1" action="{! goPlatform1 }" 
      reRender="messagePanel" disabled="{! isPlatform1Disabled }" />
<apex:commandButton value="Go Platform2" action="{! goPlatform2 }" 
      reRender="messagePanel" disabled="{! isPlatform2Disabled }" />     
<apex:commandButton value="Go Platform3" action="{! goPlatform3 }" 
      reRender="messagePanel" disabled="{! isPlatform3Disabled }" /> 

I thought that System Type class might accomplish this, but quickly realized I still needed the named classes to exist for this to work.

Type t = Type.forName('PlatformOne');
PlatformOne platform1 = (PlatformOne)t.newInstance();
isPlatform1Disabled = platform1.isButtonDisabled();         

t = Type.forName('PlatformTwo');
PlatformTwo platform2 = (PlatformTwo)t.newInstance();
isPlatform2Disabled = platform2.isButtonDisabled();

t = Type.forName('PlatformThree');
PlatformThree platform3 = (PlatformThree)t.newInstance();
isPlatform3Disabled = platform3.isButtonDisabled(); 

1 Answer 1

2

You can detect if the class is present simply by using:

t = Type.forName('PackageA','PlatformOne');
if(t != null) ...

If you want to know if feature X is specifically enabled, you need an interface or virtual class.

Interface (must be in the base class for other packages to use):

interface PlatformFeature {
    boolean isFeatureDisabled();
}

Class implementing interface:

global class PlatformOne implements PlatformFeature {
    global boolean isFeatureDisabled() {
        return false;
    }
}

Determine if the feature is available:

t = Type.forName('PackageA','PlatformOne');
isPlatform1Disabled = (t == null) || ((PlatformFeature)t.newInstance()).isFeatureDisabled();

You must log in to answer this question.

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