0

iam very new to salesforce coding..please help me to solve above error,am getting this error while writing list name as oops..

      <apex:page standardController="Opportunity"extensions="MyNewController">
       <apex:form >

       <apex:pageBlock >
       <apex:pageBlockSection title="stage section">
       <apex:pageblockSectionItem >
       <apex:outputLabel value="Stage"  />
      </apex:pageblockSectionItem>
      <apex:pageblockSectionItem >     
         <apex:inputfield value="{!opportunity.StageName}" /> 
      </apex:pageblockSectionItem>
    </apex:pageBlockSection>
    <apex:pageblockButtons location="bottom">
   <apex:commandButton value="filter" action="!filter"/>
   </apex:pageblockButtons>
 </apex:pageBlock>
  <apex:pageBlock title="opportunity fields " > 
         <apex:pageBlockTable value="{!opps}" var="opp">
         <apex:column value="{!Opp.Name}"/>
         <apex:column value="{!Opp.Account}"/>
         <apex:column value="{!Opp.Closedate}"/>
         <apex:column value="{!Opp.Probability}"/>
     </apex:pageBlockTable>     
   </apex:pageBlock>
   </apex:form>   
   </apex:page>

in controler class also am getting error,am totally new to slaesforce am trying to write this..actually my task involve that " When user selects any stage and clicks on filter button, the table should get refreshed to populate opportunities having stage equal to stage selected"

public class MyNewController {
    public opportunity opportunity{get; set;}
    public list<opportunity> opps{get; set;}

    public MyNewController(ApexPages.StandardController controller) {

        opportunity=new opportunity();
    }
    public  void  filter(){
        opps=new list<opportunity>();
        opps=[select  Name,Account Name,Close Date,Probability from opportunity where stage=:opportunity.stage];
    }
}
  • Can you provide the code for your extension controller please. – Mark Keats Apr 6 '16 at 9:57
  • 2
    FYI: opps should be public and get set property then only you can access the variable in VF page. – Ratan Paul Apr 6 '16 at 9:59
0

For the controller issue, Fields' API name should be used in the query.

Class code changes:

public class MyNewController {
    public opportunity opportunity{get; set;}
    public list<opportunity> opps{get; set;}

    public MyNewController(ApexPages.StandardController controller) {

        opportunity=new opportunity();
    }
    public  void  filter(){
        opps=new list<opportunity>();
        opps=[select  Name,Account Name,Close Date,Probability from opportunity where stageName =:opportunity.stageName]; //you need to use the API name to query the fields. StageName is the API name for the field Stage.
    }
}

For the page, format of action method on command button is wrong.

Page code changes:

<apex:page standardController="Opportunity" extensions="MyNewController">
    <apex:form >

        <apex:pageBlock >

            <apex:pageBlockSection title="stage section">
                <apex:pageblockSectionItem >
                    <apex:outputLabel value="Stage"  />
                </apex:pageblockSectionItem>
                <apex:pageblockSectionItem >     
                    <apex:inputfield value="{!opportunity.StageName}" /> 
                </apex:pageblockSectionItem>
            </apex:pageBlockSection>

            <apex:pageblockButtons location="bottom">
                <apex:commandButton value="filter" action="{!filter}"/>  <!-- It should not be "!filter"-->
            </apex:pageblockButtons>
        </apex:pageBlock>

        <apex:pageBlock title="opportunity fields " > 
             <apex:pageBlockTable value="{!opps}" var="opp">
                 <apex:column value="{!Opp.Name}"/>
                 <apex:column value="{!Opp.Account}"/>
                 <apex:column value="{!Opp.Closedate}"/>
                 <apex:column value="{!Opp.Probability}"/>
            </apex:pageBlockTable>     
        </apex:pageBlock>
    </apex:form>   
</apex:page>

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.