2

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.

Thanks,

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:pageBlock>
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Return" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockTable value="{!Element}" var="a" id="table">
        <apex:column headerValue="Name">
            <apex:inputField value="{!a.name}"/>
        </apex:column>
        <apex:column headerValue="Type">
            <apex:inputField value="{!a.vlocity_cmt__Type__c}"/>
        </apex:column>
        <apex:column headerValue="Order">
            <apex:inputField value="{!a.vlocity_cmt__Order__c}"/>
        </apex:column>
        <apex:column headerValue="Parent Element">
            <apex:inputField value="{!a.vlocity_cmt__ParentElementId__c}"/>
        </apex:column>
    </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Class

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()){ 
          elementIds.add(elm.Id);
      }
    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 ];
    }
}  

Test

@isTest
public class testElementMassEdit{

public static testMethod void testElementMassEdit(){

    PageReference pageRef = Page.MassEditElement;
    Test.setCurrentPage(pageRef);

    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);


    }
}
2

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>();
lstvcmt.add(objElement);
    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.