-5

On running the following code in apex and visualforce respectively i am receiving following error:

Error: Unknown property 'Setter_Method.Oportunities'    
Quick Fix   Create Apex property 'Setter_Method.Oportunities'
Quick Fix   Create Apex method 'Setter_Method.getOportunities'

Apex Code:

public class Setter_Method {
    public String n; 
    List<opportunity> op;

    public String getSearch(){//to return the search query again
        return n;
    }
    public List<Opportunity> getResult(){//to return the search results
        return op;
    }
    public void setOportunities(String s){//to set the search from VF to apex 
            n=s;
    }
    public PageReference display(){
        op =[SELECT Amount,Name,TotalOpportunityQuantity,probability from Opportunity WHERE name =:'n'];
        return null;
    }
}

Visual Force code:

<apex:page controller="Setter_Method">
    <apex:form >
        <apex:pageBlock >
            <apex:inputText value="{!Oportunities}"/>
            <apex:commandButton action="{!display}" value="Search Name"/>
            <apex:pageBlockTable value="{!Result}" var="op">
                <apex:column value="{!op.name}"/>
                <apex:column value="{!op.Amount}"/>
                <apex:column value="{!op.TotalOpportunityQuantity}"/>
                <apex:column value="{!op.probability  }"/>
            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Please explain the logic of getter, setter and the attribute of <apex:inputText value"">

1
  • 3
    you definitely need to complete VF trailhead module, especially this one. All answers are explained here Commented Mar 7, 2018 at 12:29

1 Answer 1

2

You are getting this error because there is no getter method defined in controller for variable "Oportunities" and it is used in VF page:

<apex:inputText value="{!Oportunities}"/>

To overcome from this error you should create getter one of the following way:

Method 1:
By Updating following line

public  List<opportunity> op { get; set; }

Method 2: By adding following method

public List<Opportunity> getOportunities(){//to return the search results
    return op;
}

For more details you can go to Simple getter setter

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .