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
Chris Morrison 7Chris Morrison 7 

Apex Output Field from Extension Controller

I am new to development and working on a VF page that will show data from Opportunity, Account and Contact Roles. The standard controller is Opportunity and have tried to build an extension to bring in the parent Account data I need. I started with a list controller and can't get the data to display in an Apex:Output field tag. I get an error that says" Unknown property 'VisualforceArrayList.Account'". It does work when using an apex:PageBlockTable and setting the value of the table to the variable. I don't need or want a table I just want an Output. Here is my controller syntax:
public class DealReviewSheetContactRoleExtension{
    public list<Opportunity> Acco{
        get;
        set;
    }
    public DealReviewSheetContactRoleExtension(
    	ApexPages.StandardController controller
    ){
        Acco = 
            [SELECT
            	Account.Name,
            	Account.AnnualRevenue,
             	Account.BillingAddress
        
            FROM
            	Opportunity
            WHERE
            	Id =
            	:((Opportunity)controller.getRecord()).Id
            ];
    }
}
and here is the relevent block on the VF page:
<apex:pageBlock >
            <apex:pageBlockSection >

                <apex:outputField value="{!Opportunity.Name}" label="Point Person:"/>
                <apex:outputField value="{!Acco.Account.AnnualRevenue}" label="Annual Revenue"/>
Any guidance would be greatly appreciated!

 
Raj VakatiRaj Vakati
Try this code .. you need to change it like below
 
<apex:outputField value="{!Opportunity.Account.AnnualRevenue}" label="Annual Revenue"/>

Complete code
 
public class DealReviewSheetContactRoleExtension{
    public list<Opportunity> Acco{
        get;
        set;
    }
    public DealReviewSheetContactRoleExtension(
        ApexPages.StandardController controller
    ){
        Acco = 
            [SELECT
             Account.Name,
             Account.AnnualRevenue,
             Account.BillingAddress
             
             FROM
             Opportunity
             WHERE
             Id =
             :((Opportunity)controller.getRecord()).Id
            ];
    }
}

Page
 
<apex:page standardController="Opportunity" extensions="DealReviewSheetContactRoleExtension">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection >
                
                <apex:outputField value="{!Opportunity.Name}" label="Point Person:"/>
                <apex:outputField value="{!Opportunity.Account.AnnualRevenue}" label="Annual Revenue"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Chris Morrison 7Chris Morrison 7
Hi Raj,

Thanks for your reply. I got the Account information to pull into the page because the standard controller allows for that. I just didn't have my syntax right. Now I am struggling to pull Opportunity Conract Roles into the page as either <apex:outputfield> or <apex:output:text>. As mentioned above it works fine if I assign the variable to PageBlock table but that's not what I need. I did some reading and I am seeing that I need to map the query results to Strings that can be referenced but I can't figure out how to do that. That may not even be the solution. All I need to do is show fields from certain Opportunity Contact records on the page. Can you help me?