3

I want to create extension class with StandardSetController.

public with sharing class AccountExtCtrl {

  private ApexPages.StandardSetController ctrl {get;set;}
  public AccountExtCtrl(ApexPages.StandardSetController controller)        
  {
    ctrl = controller;
  } 

  //todo

}

but when i use this extension to visualforce page

<apex:page standardController="Account" extensions="AccountExtCtrl">
  <!-- todo -->
</apex:page>

always print this:

common.apex.runtime.bytecode.BytecodeApexObjectType cannot be cast to common.apex.runtime.impl.ApexType

  • 1
    Try specifying your standardController as a standardSetController, or ensure you have a constructor that accepts a ApexPages.StandardController. the difference between the two is whats creating the error (and an unhelpful one at that) – battery.cord Oct 18 '16 at 15:33
10

You get this error because you are trying to cast a StandardController to a StandardSetController. Note that you can define both constructors on one extension, in which case the extension can be used for either markup approach. Note that using a StandardSetController allows you to use the page in a List Button, whereas using a StandardController allows you to use it in a Detail Button.

Works

<apex:page standardController="..." extensions="MyExtension">
public MyExtension(ApexPages.StandardController controller)
{
    // constructor logic
}

(or)

<apex:page standardController="..." recordSetVar="records" extensions="MyExtension">
public MyExtension(ApexPages.StandardSetController controller)
{
    // constructor logic
}

(or)

<apex:page standardController="..." recordSetVar="records" extensions="MyExtension">
public MyExtension(ApexPages.StandardController controller)
{
    // overloaded constructor logic
}
public MyExtension(ApexPages.StandardSetController controller)
{
    // overloaded constructor logic
}

Fails

<apex:page standardController="..." extensions="MyExtension">
public MyExtension(ApexPages.StandardSetController controller)
{
    // constructor logic
}

(or)

<apex:page standardController="..." recordSetVar="records" extensions="MyExtension">
public MyExtension(ApexPages.StandardController controller)
{
    // constructor logic
}
| improve this answer | |
  • 2
    nice explanation – Santanu Boral Oct 18 '16 at 15:54
  • 1
    @C.William If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either. – Adrian Larson Oct 18 '16 at 17:57
0

To supplement Adrian Larson's answer you can also use StandardSetController without declaring standardController or recordSetVar in the VF page.

<apex:page controller="YouController" >
private ApexPages.StandardSetController ssc;
public YourController(){
    ssc = new ApexPages.StandardSetController(
        Database.getQueryLocator([SELECT your query here... ]));
}

And then wrapping all the methods of the StandardSetController in your own functions.

public void getNext(){
    ssc.next();
}

public void getPrevious(){
    ssc.previous();
}

etc...
| improve this answer | |

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.