I am trying to create a Visualforce page that displays a list view of Opportunities that fit a certain criteria. For example, I want to show all opportunities that are sold that belong to an Account in California.

I would then like to be able to edit all fields on either the account or the opportunity object.

The fields could be something like

Account Name   Account State    Opportunity Stage   Opportunity Amount

and from this list view I could inline edit any field and save.

Could someone explain to me how this would be done? Would I need a custom controller? Or can I just use the Opportunity Standard Controller?

  • You need to use standardcontoller as Opportunity with recordsetvar and controller extension Commented May 29, 2017 at 23:36
  • Possible answer would rely on what exactly you want to update. If you are trying to update account fields, you wont be able to use the standardController, as it would only update opportunity fields, not related objects (You can change the account lookup value, but not the fields). Possible solution would be a custom controller and apex:repeat to build the table. Commented May 30, 2017 at 0:38

1 Answer 1


Yes, you need to roll your own custom controller. The standard controller class is for a single record. You give it an Id, it gives you back a record. Or if you are creating a new record, you provide a null Id.

The standard set controller is for multiple records, but you can't specify criteria in the way you want just using markup. You may need to add such a controller as an attribute on your custom controller if you want to paginate your query results.

Here's the basic structure you need at a minimum:

public with sharing class MyController
    public List<Opportunity> opportunities { get; private set; }
    public MyController()
        opportunities = [/*query records here*/];

There are many bells and whistles you might add, but the most obvious would be a text property to specify the state.

public String accountState { get; set; }

Notice I didn't use private set here. I left this one public because you'll want to bind an input to it on the page.

As far as the controller goes, those are some of the rudiments you need to understand. To get a more through walkthrough of Visualforce, Apex, and other topics you will need in order to implement this project, I recommend the Trailhead platform.


You must log in to answer this question.

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