Following is my code:


<apex:page standardController="account" extensions="ForecastHierarchyEditExtension" tabStyle="Account" sidebar="false"  standardStylesheets="false">                            
    <c:ForecastHierarchyEdit recordId="{!account.id}"/>  

VF COMPONENT used in above page:

<apex:component Controller="ForecastHierarchyController" extensions="ForecastHierarchyEditCompExtension">
    <apex:attribute name="recordId" description="Record Id" type="id" assignTo="{!record_Id}" required="true"/>
    <apex:form >
        <apex:selectList value="{!ForecastCustomerToDelete}" multiselect="false">
            <apex:selectOptions value="{!ForecastCustomers}"/>  


public class ForecastHierarchyController { 

    public account acc{get;set;}
    public id record_Id;
    public id getrecord_Id(){
         return record_Id; 

    //Following is the solution for record_Id null in the constructor
    public void setrecord_Id(id s){
        if (s!=null){
          record_Id = s;

    public ForecastHierarchyController() { 
          /*Since the constructor is called before the setter
          record_Id will always be null when the constructor is called.*/                      
          system.debug('record_Id '+record_Id);      

    public void GetData(){
        acc=[select Id
            from account
            where id=:record_Id];
        system.debug('Component Controller acct '+acc);


public class ForecastHierarchyEditCompExtension {
    public id ForecastCustomerToDelete { get; set; }
    private final ForecastHierarchyController myReference;   
    private final Account acct;

    public ForecastHierarchyEditCompExtension (ForecastHierarchyController ForecastHierarchyCtrl) {
         this.myReference = ForecastHierarchyCtrl;
          System.debug('myReference: ' + myReference);

    public List<SelectOption> ForecastCustomers{
        get {
            List<SelectOption> ForecastCustomers = new List<SelectOption>(); 
            //here acct=null
            system.debug('Component Controller Extension acct '+acct);
            if (acct!=null){
                if (acct.id!=null){             
                    for (account acc :[select id,Name from account where Forecast_Account__c=: acct.id]){
                        ForecastCustomers.add( new SelectOption( acc.id, acc.Name ) ); 
            return ForecastCustomers;
        private set;


enter image description here

I know that we cannot access the attribute record_Id in the constructor of the VF component controller (null value) so i m setting it with

public void setrecord_Id(id s){

How can i pass record_Id to the component extension controller ? I mean to ForecastHierarchyEditCompExtension constructor.

I would like to get populate myReference.acc or myReference.record_Id so that also List ForecastCustomers will be populated.

Actually List is not populated because acct is null.

Thanks in advantage for any advice.

  • I'm not sure yet why record_Id is null, but I think I see a problem that hasn't come up yet: The extension constructor references acc in the custom controller, but, at the time the extension constructor runs, acc won't have been set. (Both constructors will run before the getters/setters, and acc is set by GetData(), which is called by setrecord_ID.) – Shane Steinfeld Dec 26 '14 at 17:39
  • Yes Shane, that is the problem that i m trying to solve. – Enry Dec 26 '14 at 17:43
  • Oh. Oops! I was focused on the null mystery. :P – Shane Steinfeld Dec 26 '14 at 17:50
  • Did you find a solution ? – SF_user Mar 2 '15 at 12:50

Your Answer

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

Browse other questions tagged or ask your own question.