2

I want to Render a section of my Visualforce page only if I found Opportunities related to the Account I'm working with and I'm getting this error message. I have a VF Page and a controller extension.

    <apex:page standardController="Account" extensions="MyControllerExtension" action="{!init}">
    <apex:form>
        <apex:pageBlock TITLE="Company" id="theBlock">
            <apex:outputText value="Have you created a new opportunity "/>
            <apex:pageBlockSection columns="1">
               <!-- <apex:selectRadio value="{!BooleanOptions}">
                    <apex:selectOptions value="{!yesNo}"/>
                </apex:selectRadio > -->
            </apex:pageBlockSection>
        </apex:pageBlock>

        <apex:pageBlockSection Title="Opportunities related to this Account" rendered="{!hasOpp}">
            <apex:pageBlockTable value="{!showOpps}" var="opp" width="500">
                <apex:column headervalue="Opportunity Name" value="{!opp.Name}" />
                <apex:column headerValue="Closed Date" value="{!opp.CloseDate}" />
                <apex:column headerValue="Opportunity Stage"  value="{!opp.StageName}" />
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:form>
    <apex:pageMessages ></apex:pageMessages>
    <apex:outputField value="{!Account.Name}" rendered="false" />
    <apex:outputField value="{!Account.MasterId__c}" rendered="false" />
    <apex:outputField value="{!Account.CDS_Company_ID__c}" rendered="false" />
    <apex:outputField value="{!Account.OwnerId}" rendered="false" />
</apex:page>

This is the controller ext:

public with sharing class MyControllerExtension {
    private final Account acct;

    public MyControllerExtension(ApexPages.StandardController stdController) {
        this.acct = (Account) stdController.getRecord();
    }

    /*public List<SelectOption> getYesNo() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('true', 'Yes'));
        options.add(new SelectOption('false', 'No'));
        return options;
    } */

    public boolean hasOpp {
       get {
           List<Opportunity> oppList = new List<Opportunity>([SELECT Id FROM Opportunity WHERE Account.Id = :acct.Id]);
           return (oppList.IsEmpty());
       }
        private set;
    }

    public List<Opportunity> showOpps() {
        List<Opportunity> oppList = new List<Opportunity>();

        if (acct.Id != null){
            oppList = [SELECT Name, Amount, CloseDate, StageName FROM Opportunity WHERE Account.Id =: acct.Id ];
            return oppList;
        } else {
            oppList = null;
            return oppList;
        }
    }

    public PageReference init() {
        String CompanyId = acct_Company_ID__c;
        if (String.isEmpty(CompanyId)) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO, 'The new account setup process is not yet available for this company. Please try again in a few minutes.'));
            return null;
        }

        System.debug('salesforceId:' + acct.Id);

        // Get "Landing Page" where user will be taken to open or check existing account.
        PageReference page = new PageReference(EnvironmentSettings.getOpenAccountUrl());
              page.getParameters().put('salesForceId', acct.Id);

        page.setRedirect(true);
        return page;
    }

}

The error is thrown on this line in my VF Page:

<apex:pageBlockSection Title="Opportunities related to this Company" rendered="{!hasOpp}">

Even though I have a get and set on hasOpp (in my ext controller), not sure what I'm missing. Thanks.

  • what's the error message? – night crawler Apr 11 '17 at 18:04
  • Error is with showOpps, its must be getShowOpps() in controller – Raul Apr 11 '17 at 18:05
2

The line of markup that is actually throwing your error is one further down:

<apex:pageBlockTable value="{!showOpps}" ...>

The reason is that you declared showOpps as a method, not a property.

Method Syntax

public List<Opportunity> showOpps()
{
    // cannot reference showOpps as a property
}

Property Syntax

public List<Opportunity> getShowOpps()
{
    // can reference showOpps as a property
}

Getter Syntax

public List<Opportunity> showOpps
{
    get
    {
        // can reference showOpps as a property
    }

    private set;
    // having any setter is optional
    // use the private access modifier if you do declare one
    // there's no good reason to leave it public
}
  • @TheGhost If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either. – Adrian Larson Apr 11 '17 at 18:43

Your Answer

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

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