0

I have Custom Controller I want to call with a Custom Button on the Opportunity Page. The Custom Controller will get the Opportunity Id from the Opportunity page.

I getting this errors: 1.Unknown property 'OpportunityStandardController.opportunities' 2.Constructor not defined: [ApexPages.StandardController].(List)

Apex class:

public class updateoppty {
    List<Opportunity> opportunities = new List<Opportunity>();
    public updateoppty(ApexPages.StandardController sc){
        opportunities = [SELECT Id,Name,Account.Name,StageName FROM opportunity WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

public List<Opportunity> getOpptyDetail(){
    return opportunities;
}

public PageReference save() {
    try{
        upsert(opportunities);
    }
    catch(System.DmlException e){
        ApexPages.addMessages(e);
         return null;
    }
   
}
Pagereference view = new ApexPages.StandardController(opportunities).view();
return (view);
 }

VS Code:

<apex:page standardController="Opportunity" extensions="updateoppty" tabStyle="Opportunity">
    <apex:form id="opptyForm">
        <apex:pageBlock title="Opportunity_list">
            <apex:pageBlockSection>
            <apex:pageBlockTable value="{!opportunities}" var = "opporty">
                <apex:inputField value = "{!opporty.Name}"/>
                <apex:inputField value = "{!opporty.Account.Name}"/>
                  <apex:inputField value = "{!opporty.StageName}"/>    
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            <apex:commandButton action="{!Save}" value="Save"/>
                </apex:pageBlock>
    </apex:form>
</apex:page>

Please anyone help me to solve this error.

2
  • 2
    The opportunities does not have a public getter in your code.
    – manjit5190
    Commented Jun 27, 2020 at 16:55
  • 1
    @manjit5190- that's the answer - please add it
    – cropredy
    Commented Jun 27, 2020 at 18:03

1 Answer 1

0

The opportunities does not have a public getter in your code. So you can either create a method of just do

public List<Opportunity> opportunities {get;set;}

2
  • Now It doesn't throw error but it didn't show any fields in opportunity.It only show save button .When I click the save button it throws some message Could not resolve the entity from <apex:inputField> value binding '{!opporty.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable. and one more point I want to update my opportunity using custom button.Please help me to solve this issue.
    – Jane
    Commented Jun 28, 2020 at 9:55
  • You cannot put apex:inputfield as a direct child of apex:pageBlockTable, you need to put it inside apex:column. Commented Jun 28, 2020 at 13:18

You must log in to answer this question.

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