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);
}
}
Best Answer
This looks like a simple syntax error in your code
You will need to Instantiate your extension controller class rather than some unknown name