Find your content:

Search form

You are here

Do methods returning APEX classes live in a different namespace?

 
Share

I have a controller class, below.

It is passed in "thePpt" as an SOBJECT, and the class has access to it in the getGuam method, but not the initPhoneList or GetDaytimePhoneList() methods. WHY?

They return an Apex object, not a String? I'm guessing that I am in the wrong namespace or something. Please help!

public with sharing class FFGEHeader {

public Participant__c thePpt {get; set{ thePpt=value;}}

public String daytimePhone {get;set;}
public String altPhone {get;set;}
public String guam {set;}

public String getGuam()
{
    if (thePpt != null)
        return 'Guam';
    else
        return 'NULL PPT';
}



public Component.Apex.SelectList initPhoneList()
{
    System.Debug('*** initPhoneList. Trying to see ppt object  ***');
    Component.Apex.SelectList selPhoneList = new Component.Apex.SelectList(id = daytimePhone , multiselect = false, size = 1, style = 'width:200px;');
    if (thePpt != null)
    {
    if (thePpt.Home_Phone__c != null)
        AddSelectOption(selPhoneList, 'Home Phone',thePpt.Home_Phone__c);
    if (thePpt.Cell_Phone__c != null)
        AddSelectOption(selPhoneList, 'Cell Phone',thePpt.Cell_Phone__c);
    if (thePpt.Work_Phone__c != null)
        AddSelectOption(selPhoneList, 'Work Phone',thePpt.Work_Phone__c);
    } else
        System.Debug('*** the PPT OBJECT IS NULL. WHY??????????  ***');

    return selPhoneList;

}
public Component.Apex.PageBlockSectionItem GetDaytimePhoneList()   
{   
    System.Debug('*** GetDaytimePhoneList  ***');
    Component.Apex.SelectList selPhoneList =  this.initPhoneList();

    Component.Apex.PageBlockSectionItem dayPhoneList = new Component.Apex.PageBlockSectionItem();
    //Component.Apex.SelectList selPhoneList = new Component.Apex.SelectList(id = daytimePhone , multiselect = false, size = 1, style = 'width:200px;');
    selPhoneList.expressions.value='{!daytimePhone}';
    /*if (myPpt.Home_Phone__c != null)
        AddSelectOption(selPhoneList, 'Home Phone',thePpt.Home_Phone__c);
    if (myPpt.Cell_Phone__c != null)
        AddSelectOption(selPhoneList, 'Cell Phone',thePpt.Cell_Phone__c);
    if (thePpt.Work_Phone__c != null)
        AddSelectOption(selPhoneList, 'Work Phone',thePpt.Work_Phone__c);
    */
    /*if (myPpt != null)
    {
        AddSelectOption(selPhoneList,'Home Phone','3037795645');
        AddSelectOption(selPhoneList,'Cell Phone','7207793211');
        AddSelectOption(selPhoneList,'Work Phone','3037795645');
    }   */
    dayPhoneList.childComponents.add(selPhoneList);
    return dayPhoneList;
}

Attribution to: DVC variable scope

Possible Suggestion/Solution #1

If your using this class with bindings to components on a Visualforce page. This might be a case of the indeterminate order in which in the Visualforce runtime calls the get/set methods. For example it may be that Visualforce is calling your 'initPhoneList' and 'GetDaytimePhoneList' methods before the setter for the 'thePpt' variable.

If your controller contains an instance of the FFGEHeader, I would suggest you explicitly initialise the 'thePpt' member either by adding a constructor to your 'FFGEHeader' class or by doing so immediately after the code that creates it.

This article Getter Method Order and Visualforce Pages appears to explain it pretty well. Basically avoid get/set methods with side effects. Personally I tend not to have them do anything or depend on anything my constructor is not all ready setting up.


Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4316

My Block Status

My Block Content