I have created a fairly basic VF page and controller extension class as follows. I am trying to write a test class so that this can be deployed, but keep getting an "invalid type" error in the test class.

I have spent hours trying to figure out why. Any help would be appreciated.


Visualforce Page

<apex:page standardController="vlocity_cmt__Element__c" recordSetVar="Element" sidebar="false" extensions="ElementSort" >

<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
    <apex:pageMessages />
    <apex:pageBlock >
        Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Return" action="{!cancel}"/>
    <apex:pageBlockTable value="{!Element}" var="a" id="table">
        <apex:column headerValue="Name">
            <apex:inputField value="{!a.name}"/>
        <apex:column headerValue="Type">
            <apex:inputField value="{!a.vlocity_cmt__Type__c}"/>
        <apex:column headerValue="Order">
            <apex:inputField value="{!a.vlocity_cmt__Order__c}"/>
        <apex:column headerValue="Parent Element">
            <apex:inputField value="{!a.vlocity_cmt__ParentElementId__c}"/>


public class ElementSort
  public list<vlocity_cmt__Element__c> elementList{get;set;}
  public ApexPages.StandardSetController standardController;
  private Set<Id> elementIds = new Set<Id>();

  public ElementSort(ApexPages.StandardSetController standardController){
      this.standardController = standardController;
      elementList = new List<vlocity_cmt__Element__c>();
      for (vlocity_cmt__Element__c elm : (List<vlocity_cmt__Element__c>)standardController.getSelected()){ 
    elementList = [SELECT Name,vlocity_cmt__Type__c,vlocity_cmt__Order__c,vlocity_cmt__ParentElementId__c FROM vlocity_cmt__Element__c WHERE ID IN: elementIds ORDER BY vlocity_cmt__Order__c ];


public class testElementMassEdit{

public static testMethod void testElementMassEdit(){

    PageReference pageRef = Page.MassEditElement;

    vlocity_cmt__OmniScript__c objVOS = new vlocity_cmt__OmniScript__c();

    objVOS.Name = 'Test';
    insert objVOS;

    vlocity_cmt__Element__c objElement = new vlocity_cmt__Element__c();

    objElement.vlocity_cmt__OmniScriptId__c = objVOS.Id;
    objElement.Name = 'Test Element';
    objElement.vlocity_cmt__Type__c = 'Step';
    objElement.vlocity_cmt__Order__c = 1;

    insert objElement; 

    ApexPages.StandardController theElements = new ApexPages.StandardController(objElement);

    //* Getting "Error: Compile Error: Invalid type: myExtension here:
    myExtension ext = new myExtension(theElements);


This looks like a simple syntax error in your code

You will need to Instantiate your extension controller class rather than some unknown name

//* Getting "Error: Compile Error: Invalid type: myExtension here:
//myExtension ext = new myExtension(theElements);Not correct code 
list<vlocity_cmt__Element__c> lstvcmt=new list<vlocity_cmt__Element__c>();
    ApexPages.StandardSetController theElements = new ApexPages.StandardSetController(lstvcmt);
ElementSort ext=new ElementSort(theElements);//Your extension Controller instantiation
| improve this answer | |
  • Thanks. I see what you are getting at, but I made the change and now am getting: Compile Error: Constructor not defined: [ElementSort].<Constructor>(ApexPages.StandardController) – David W May 17 '15 at 15:24
  • You will need to instantiate standard set controller not standard controller – Mohith Shrivastava May 17 '15 at 15:40
  • Thanks. I tried that and now I get: Constructor not defined: [ApexPages.StandardSetController].<Constructor>(vlocity_cmt__Element__c) – David W May 17 '15 at 16:20
  • Please paste your updated code – Mohith Shrivastava May 17 '15 at 16:30
  • 1
    Thanks. It compiled, but I have to step away right now. I will let you know later today. Thanks again! – David W May 17 '15 at 16:39

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.