You need to sign in to do that
Don't have an account?
DRobi83
Help with Test Class
Hello
I am trying to write a test class within this apex class. I have used it before but for some reason this time it is not working. Any ideas?
My error is
Error: InvoiceCloneWithItemsController Compile Error: Method does not exist or incorrect signature: [InvoiceCloneWithItemsController].getInvoiceCloneWithItemsController() at line 68 column 5
public class InvoiceCloneWithItemsController {
//added an instance varaible for the standard controller
private ApexPages.StandardController controller {get; set;}
// add the instance for the variables being passed by id on the url
private miiFinance__Invoice__c po {get;set;}
// set the id of the record that is created -- ONLY USED BY THE TEST CLASS
public ID newRecordId {get;set;}
// initialize the controller
public InvoiceCloneWithItemsController(ApexPages.StandardController controller) {
//initialize the stanrdard controller
this.controller = controller;
// load the current record
po = (miiFinance__Invoice__c)controller.getRecord();
}
// method called from the VF's action attribute to clone the po
public PageReference cloneWithItems() {
// setup the save point for rollback
Savepoint sp = Database.setSavepoint();
miiFinance__Invoice__c newPO;
try {
//copy the purchase order - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
po = [select Id, Name, miiFinance__Customer__c, Charged_To_Credit_Card__c, miiFinance__Company_Name__c, miiFinance__Currency__c, miiFinance__Description__c, miiFinance__Due_Date__c, Payment_Allocation__c, miiFinance__Type__c from miiFinance__Invoice__c where id = :po.id];
newPO = po.clone(false);
insert newPO;
// set the id of the new po created for testing
newRecordId = newPO.id;
// copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
List<miiFinance__Invoice_Line_Item__c> items = new List<miiFinance__Invoice_Line_Item__c>();
for (miiFinance__Invoice_Line_Item__c pi : [Select p.Id, p.Name, miiFinance__Amount_Inc_Tax__c, Billed_From_Subscription__c, miiFinance__Currency__c, miiFinance__Display_Name__c, miiFinance__Product_For_Sale__c, miiFinance__Quantity__c, miiFinance__Tax__c, Tax_Amount_Dollars__c From miiFinance__Invoice_Line_Item__c p where miiFinance__Invoice__c = :po.id]) {
miiFinance__Invoice_Line_Item__c newPI = pi.clone(false);
newPI.miiFinance__Invoice__c = newPO.id;
items.add(newPI);
}
insert items;
} catch (Exception e){
// roll everything back in case of error
Database.rollback(sp);
ApexPages.addMessages(e);
return null;
}
return new PageReference('/'+newPO.id+'/e?retURL=%2F'+newPO.id);
}
public static testmethod void Test1()
{
miiFinance__Invoice__c p=new miiFinance__Invoice__c();
ApexPages.StandardController sc = new ApexPages.standardController(p);
InvoiceCloneWithItemsController po=new InvoiceCloneWithItemsController (sc);
po.getInvoiceCloneWithItemsController();
}
}
here is my vf page
<apex:page standardController="miiFinance__Invoice__c" extensions="InvoiceCloneWithItemsController" action="{!cloneWithItems}"> <apex:pageMessages /> </apex:page>
Hi,
I have seen there is no any method with name getInvoiceCloneWithItemsController() inside your class. That’s why you are getting this error.
I think it should be:
po.cloneWithItems() instead of po.getInvoiceCloneWithItemsController()
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
You are calling the method without any parameters in your test class whereas in your class the method has a paramter defined.
Hi,
I have seen there is no any method with name getInvoiceCloneWithItemsController() inside your class. That’s why you are getting this error.
I think it should be:
po.cloneWithItems() instead of po.getInvoiceCloneWithItemsController()
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.