2

I am attempting to convert my page to work from List View button into Detail Page button.

When I attempt to remove the recordsetvar, I get the mentioned error.

Unknown constructor 'AddBasketGasQuoteFromMonitor.AddBasketGasQuoteFromMonitor(ApexPages.StandardSetController controller)

Below are pieces of code:

VF

<apex:page standardController="Line_del__c" recordSetVar="recrec" extensions="AddBasketGasQuoteFromMonitor">

Apex

  public with sharing class AddBasketGasQuoteFromMonitor{
    Public List<WrapperClassEx> WrapperList{get;set;}
    public AddBasketGasQuoteFromMonitor(ApexPages.StandardSetController controller) {
      mycon = controller;
      Selectedmeters = mycon.getSelected();
    }
    public List<sobject> Selectedmeters {get; set;} 
    ApexPages.StandardSetController mycon; 
   Public List<WrapperClassEx> getwrapperObj(){
      List<electricity_meter__c> MeterList = [Select id,name,AQ__c,meter_details__c from electricity_meter__c where Linked_Monitor_Line__c in: SelectedMeters]; 

The last line is where I need to use my ID (should be Linked_Monitor_Line__c=SelectedMeters). I know I can get the Id by doing something like: Id recordId = standardController.getId(); but I realize in this case it's different?

1
  • Please be more specific - I currently can't understand what you want to achieve. Could you provide us with more data or edit your question? Feb 21, 2014 at 15:33

2 Answers 2

5

According to Building a Controller Extension I think you should have a constructor with ApexPages.StandardController as a parameter:

public with sharing class AddBasketGasQuoteFromMonitor{
    Public List<WrapperClassEx> WrapperList{get;set;}
    public AddBasketGasQuoteFromMonitor(ApexPages.StandardController controller) {
      // this is new constructor which should fix your problem
    }
    public AddBasketGasQuoteFromMonitor(ApexPages.StandardSetController controller) {
      mycon = controller;
      Selectedmeters = mycon.getSelected();
    }
    public List<sobject> Selectedmeters {get; set;} 
    ApexPages.StandardSetController mycon; 
   Public List<WrapperClassEx> getwrapperObj(){
      List<electricity_meter__c> MeterList = [Select id,name,AQ__c,meter_details__c from electricity_meter__c where Linked_Monitor_Line__c in: SelectedMeters];
2
  • Thank you so much, this solved my problem completely! Can you just explain what I have done here?
    – dzh
    Feb 21, 2014 at 16:22
  • I think you can still use your controller for set of data. But sfdc insist on constructor with standard controller. Feb 21, 2014 at 16:38
2

If you are not using recordSetVar then your Controller Extension constructor needs to take an ApexPages.StandardController argument rather than a ApexPages.StandardSetController argument.

See the documentation here for more information.

A controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend.

You can then get the current record using the StandardController.getRecord() method which is documented here.

getRecord()
Returns the record that is currently in context, based on the value of the id query string parameter in the Visualforce page URL.

You must log in to answer this question.

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