+ Start a Discussion
JN22JN22 

Pull Fields from Extension

Hello,

 

This is probably a simple answer, but I am getting an error when I try to create a VF page using pageBlockSections.  My page has the Account as the standard controller and a custom controller to pull through the Account Name to the data I am entering for my custom object (Client Status__c).  When I try to save, i get the error:   Error: Unknown property 'AccountStandardController.Client_Status__c'.  Can anyone help?  My code is below:

 

<apex:page standardController="Account" tabStyle="Account" extensions="StatusController">
   <apex:form >
    <apex:pageBlock title="Client Status">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="detail" />
            </apex:pageBlockButtons>

            <apex:pageBlockSection title="GENERAL INFORMATION" columns="2">
                    Client Name:
                    <apex:outputField value="{!score.Client_Name__c}" />
                    The Client is a(n):
                    <apex:inputField value="{!score.Type_of_Client__c}"/>
                    The Client Licenses:
                    <apex:inputField value="{!score.Client_Licenses__c}"/>
            </apex:pageBlockSection>
       </pageBlock>

   </Form>

</Page>

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

So in this controller, score is a list of Client_Status__c records, but in your page you are attempting to use it as an instance:

 

   <apex:outputField value="{!score.Client_Name__c}" />

 

The error message is a bit weird, but essentially the problem is that a list doesn't have a property named Client_Name__c.  I would say you should either be iterating the list:

 

<apex:page standardController="Account" tabStyle="Account" extensions="StatusController">
   <apex:form >
    <apex:pageBlock title="Client Status">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="detail" />
            </apex:pageBlockButtons>

            <apex:pageBlockSection title="GENERAL INFORMATION" columns="2">
                <apex:repeat value="{!score}" var="stat">
                    Client Name:
                    <apex:outputField value="{!stat.Client_Name__c}" />
                    The Client is a(n):
                    <apex:inputField value="{!stat.Type_of_Client__c}"/>
                    The Client Licenses:
                    <apex:inputField value="{!stat.Client_Licenses__c}"/>
                </apex:repeat>
            </apex:pageBlockSection>
       </pageBlock>
   </Form>
</Page>
 

or change the controller so that score is a single instance of a Client_Status__c record. 

 

All Answers

bob_buzzardbob_buzzard

Can you post the controller code?  This usually means that the field/property you are trying to access isn't exposed properly from the extension controller.  The error message is a bit confusing as the platform always assumes the field/property should be coming from the standard controller.

JN22JN22

Hi Bob,

 

My controller is below:

 

public class ScorecardController{

public List<Client_Status__c> score {get; set;}
    private final Account acct;
    public ScorecardController(ApexPages.StandardController myController) {
        acct=(Account)myController.getrecord();
                  
        score = new List<Client_Status__c>();
        Client_Status__c score2 = new Client_Status__c();
               score2.Client_Name__c = acct.id;
        score.add(score2);}


    public PageReference save() {
        insert score;
        PageReference RetPage = new PageReference('/' + score[0].id);
        RetPage.setRedirect(true);
        return RetPage; }

}

bob_buzzardbob_buzzard

So in this controller, score is a list of Client_Status__c records, but in your page you are attempting to use it as an instance:

 

   <apex:outputField value="{!score.Client_Name__c}" />

 

The error message is a bit weird, but essentially the problem is that a list doesn't have a property named Client_Name__c.  I would say you should either be iterating the list:

 

<apex:page standardController="Account" tabStyle="Account" extensions="StatusController">
   <apex:form >
    <apex:pageBlock title="Client Status">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="detail" />
            </apex:pageBlockButtons>

            <apex:pageBlockSection title="GENERAL INFORMATION" columns="2">
                <apex:repeat value="{!score}" var="stat">
                    Client Name:
                    <apex:outputField value="{!stat.Client_Name__c}" />
                    The Client is a(n):
                    <apex:inputField value="{!stat.Type_of_Client__c}"/>
                    The Client Licenses:
                    <apex:inputField value="{!stat.Client_Licenses__c}"/>
                </apex:repeat>
            </apex:pageBlockSection>
       </pageBlock>
   </Form>
</Page>
 

or change the controller so that score is a single instance of a Client_Status__c record. 

 

This was selected as the best answer
JN22JN22

Thanks Bob, that did the trick!!

JN22JN22

Hi Bob,

 

Sorry, 1 other question.  If I wanted to put an IF condition on a pageSectionItem in this page, how would I need to call the variable?  Below is the line I am trying to code but it won't recognize the variable:

 

                <apex:pageBlockSectionItem rendered="{!IF(stat.Type_of_Client__c <> 'Health','true','false')}">

BobBBobB

I have a question as well. In the original post the first line is:

<apex:page standardController="Account" tabStyle="Account" extensions="StatusController">

which says the name of the controller ext is "StatusController"

 

But the first line of the posted Controller is:

public class ScorecardController{

...a different name.

 

What am I missing?

 

tia... Bob

JN22JN22
Sorry about that, I changed the controller name after my initial post. ScorecardController is correct.
bob_buzzardbob_buzzard

That looks about right for conditionall rendering the section.  What error do you get?

JN22JN22

Hi Bob,

 

It seems to be working now.  I must have had some bad code somewhere.  Thanks for your help!!