function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JasonFungJasonFung 

Controller Extensions and Custom Controllers

I have a custom controller that retrieves some data

 

public class customControllerToGetData {

 

        ...Query and Return data for a particular Account

 

}

 

This is then connected to a VF page HOME:

 

<apex:page sidebar="false" showHeader="false" Controller="customControllerToGetData">

 

       ...Show The Account From The Query In The customControllerToGetData class

 

</apex:page>

 

The user then navigates to another VF page (SHOWCUSTOMDATA) that has an extension

 

<apex:page sidebar="false" showHeader="false" Controller="customControllerToGetData" extensions="customExtension">

 

      ...Use the Account from the customControllerToGetData class and consume this in the customExtension class and show record from a customData object

 

</apex:page>

 

The class for the extension is below:

 

public class customExtension {

 

      private final customControllerToGetData controlreference;

 

      public customExtension(customControllerToGetData customController) {

            this.controlreference=customController;

      }

 

      public List<customData> getCustomData() {

            List<customData> lstCustom = Database.query('Select Id, Account__c from customData where Account__c In :controlreference.Account');

      }

 

}

 

This functions as intended.

 

HOWEVER, when I then navigate to a 3rd VF page (SHOWCUSTOMDATAALTERNATE) that is identical in functionality to the above controller extension with the same constructor and query:

 

<apex:page sidebar="false" showHeader="false" Controller="customControllerToGetData" extensions="customExtensionAlternate">

 

      ...Use the Account from the customControllerToGetData class and consume this in the customExtensionAlternate class and show record from a customDataAlternate object

 

</apex:page>

 

with the class:

 

public class customExtensionAlternate {

 

      private final customControllerToGetData controlreference;

 

      public customExtensionAlternate(customControllerToGetData customController) {

            this.controlreference=customController;

      }

 

      public List<customData> getCustomDataAlternate() {

            List<customData> lstCustom = Database.query('Select Id, Account__c from customDataAlternate where Account__c In :controlreference.Account');

      }

 

}

 

The constructor in the customExtensionAlternate does not consume the customControllerToGetData controller in the constructor. It simply passes nothing and thus the query being called in the class that need to reference the Account cannot do so.

 

I'm at a loss here...

 

I'm basically calling a return Page.HOME, then return PAGE.SHOWCUSTOMDATA, then return a PAGE.SHOWCUSTOMDATAALTERNATE. The last page will always issue a attempt to de-reference a null object error. I don't understand how one extension consumes the original custom controller in its constructor properly and the other extension does not. The constructors are identical in both extensions.

 

If anyhow can help me out here, that would be much appreciated.

 

 

JasonFungJasonFung

To follow-up, what I've done now is simply refer to the original extension customExtension on the 3rd VF page (SHOWCUSTOMDATAALTERNATE)

 

from:

 

<apex:page sidebar="false" showHeader="false" Controller="customControllerToGetData" extensions="customExtensionAlternate">

 

to:

 

<apex:page sidebar="false" showHeader="false" Controller="customControllerToGetData" extensions="customExtension">

 

and add my logic to the original extension.

 

I'd like to know why this happens......