Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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;
}
share|improve this question
    
please include the code that shows how you are calling this class. –  superfell Nov 12 '12 at 22:46
add comment

1 Answer 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.

share|improve this answer
    
Thank you Andrew-fawcett, –  DVC variable scope Nov 13 '12 at 21:40
    
No problem! Did this answer your question then? If so great! –  Andrew Fawcett Nov 13 '12 at 21:45
    
So that others can get the benefit of this, maybe consider rephrasing your question, e.g. "Issues arising with get/set methods in controllers being called in indeterminate order?" –  Andrew Fawcett Nov 13 '12 at 21:47
    
This answer, and the article does help alot in explaining the problem with the getters and setters being called at different times during the lifecycle of the page. JSF has the same issues. And I did verify that in fact, that is what is happening. However, I still cannot access the SObject that I passed to the Component. I cannot get thePpt object to be populated no matter what I try. I tried calling the getter of the object in the constructor and that doesn't even work. So, it appears as if I just cannot force that object to get set before the dynamic component. Can you think of anything else –  DVC variable scope Nov 13 '12 at 22:08
1  
Can you extend your question with your containing page and any relevant Apex code? –  Andrew Fawcett Nov 13 '12 at 22:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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