You need to sign in to do that
Don't have an account?
dileep1.392893620949561E12
How to call Webservice Method in test class
Hi,
I have a custom button on a vf page, which will call the Webservie class (Note: webserice class doesn't make any webservice callouts) and i need to create a test class for the Webservice class inorder to create a package.
Now the problem is how to call the webservie method in my test class?
The Webservice class looks like this:
Global class MyClass
{
webservice static string insertRec(string Id)
{
-----------
-----------
}
}
I tried to call the webservice call in my testclss like this:
Myclass mc=new Myclass();
mc.insertRec();
ERROR: Method doesn't exist or incorrect signature [myclass].insertRec().
Any help would be much appreciated.
I have a custom button on a vf page, which will call the Webservie class (Note: webserice class doesn't make any webservice callouts) and i need to create a test class for the Webservice class inorder to create a package.
Now the problem is how to call the webservie method in my test class?
The Webservice class looks like this:
Global class MyClass
{
webservice static string insertRec(string Id)
{
-----------
-----------
}
}
I tried to call the webservice call in my testclss like this:
Myclass mc=new Myclass();
mc.insertRec();
ERROR: Method doesn't exist or incorrect signature [myclass].insertRec().
Any help would be much appreciated.
This is slightly different, see the links below for sample code and more information,
Testing Web Service Callouts
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm
Apex Web Services and Callouts
https://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts
Test Methods and Apex Callouts
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
See the discussion threads,
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008z4VIAQ
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008xWxIAI
Regards,
Ashish
For the global class you dont need to create an object . Just use class name and call the method directly .
Like : MyClass.insertRec('Pass respective ID here');
Thanks ,
Ajay
Fisrt you need to create a public/global class that implements the WebServiceMock interface. In this class you need to implement the "doInvoke()" method and prepare your false response.
Once you are done with this next you need to call the "Test.setMock(param1, param2)" from your test method.
param1 = WebServiceMock.class
param2 = Instance of the class that implemented the WebServiceMock interface.
Hope this helps.
Thanks,
Kaustav