function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MubarakMubarak 

Method does not exist

Test Class
@isTest
Public Class AddRowControllerTest{
Static testmethod void Addrow(){
List<Contact>con=new List<Contact>();
Contact c=new contact();
c.firstname='Test';
c.lastname='Test';
Con.add(c);
insert con;
System.AssertEquals(c.firstname,'Test');
System.AssertEquals(c.lastname,'Test');
system.test.startTest();
AddRowController arc=new AddRowController();
arc.AddRowController(con);
arc.AddRow(con);
System.test.stopTest();

}
}

Apex Class.
public class AddRowController {

Public Contact contact{get;set;}
Public list<Contact> listContact{get;set;}

Public AddRowController(){
Contact contact=new Contact();
List<Contact>listContact=new list<Contact>();
listContact.add(contact);

}
Public  void AddRow(){
Contact con=new Contact();
listContact.add(con);
}

public PageReference saveContact() {
for(Integer i=0; i<listContact.size(); i++)
{
insert listContact;
}
return Page.Properties;
}
}
.In test class without 2 methods addRowController() and addRow() am getting 28%code coverage bt if i included these two methods am getting error like Method does not exist or incorrect signature.
Note:I dont have any other class with name "Test".

can anyone tell me what might be the reason for this error in test class.


Thanks
Navneet kNavneet k
Remove - arc.AddRowController(con);
Replace arc.AddRow(con); to arc.AddRow();
Raju mancheRaju manche
In the test class you have to call the class as below

ApexPages.StandardController sc = new ApexPages.StandardController(con);
AddRowController arc=new AddRowController(sc);
arc.AddRowController();
arc.AddRow();
................................
Because you are in the methods you should not pass any values. Because in the main class there is no passing any values.
Please try this.
Thanks

 
ManojjenaManojjena
Hi Mubarak ,

You are doing two mistake in your test class .
1.AddRow is a method without parameter, however you are  passing parameter to that .
arc.AddRow();
2.AddRowController is your constructor you can not call like below .
remove below line and call the save method it will work .
arc.AddRowController(con);

Let me know any issue .

 
MubarakMubarak
Even Tried without passing the parameter in Addrow()  method but i am getting same error.
Raju mancheRaju manche
Hi Mubarak ,

In my reply I posted 
arc.AddRowController(); Please remove this part and test.
Thanks
 
Navneet kNavneet k
You have to do two following changes:
Remove - arc.AddRowController(con);
Replace arc.AddRow(con); to arc.AddRow();
Amit Chaudhary 8Amit Chaudhary 8
Hi Mubarak,

Your Class should be
public class AddRowController 
{
	Public Contact cont{get;set;}
	Public list<Contact> listContact{get;set;}

	Public AddRowController()
	{
		cont = new Contact();
		List<Contact> listContact=new list<Contact>();
		listContact.add(contact);
	}
	
	Public  void AddRow()
	{
		 listContact.add(con);
	}

	public PageReference saveContact() 
	{
		if(listContact.size() > 0)
		{
			insert listContact;
		}
		return Page.Properties;
	}
}

and test Class as :-
@isTest
Public Class AddRowControllerTest
{
	Static testmethod void Addrow()
	{
		Contact c=new contact();
		c.firstname='Test';
		c.lastname='Test';

		System.AssertEquals(c.firstname,'Test');
		System.AssertEquals(c.lastname,'Test');

		system.test.startTest();

		AddRowController arc=new AddRowController();
		arc.cont = c;
		
		arc.AddRow();
		arc.saveContact();
		
		System.test.stopTest();

	}
}
NOTE: This code has not been tested and may contain typographical or logical errors

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

Thanks,
Amit Chaudhary