6

when i try to save the following code, i got the error below. Following same instructions given in this link, but still errors. Am i doing anything wrong here? please suggest.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm

@isTest
private class WebSvcCalloutTest {
    @isTest static void testEchoString() {
        Account a = new Account(name='Tester',SAP_KUNNR__c='1172');
        insert a;              
        // This causes a fake response to be generated
        Test.setMock(WebServiceMock.class, new WebServiceMockImpl());

    }
}

Error:

Save error: Method does not exist or incorrect signature: Test.setMock(Type, WebServiceMockImpl) WebSvcCalloutTest.cls

    @isTest
global class WebServiceMockImpl implements WebServiceMock {
   global void doInvoke(
           Object stub,
           Object request,
           Map<String, Object> response,
           String endpoint,
           String soapAction,
           String requestName,
           String responseNS,
           String responseName,
           String responseType) {

        sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00 sap1 = new sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00();       
        Map<String,String> mapSAP = new Map<String,String> {};
        sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01 req = new sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01();      

       sapComDocumentSapSoapFunctionsMcS.ZGssmwfmHndlEvntrqst00Response_element ret =  sap1.ZGssmwfmHndlEvntrqst00('',req);

       response.put('response_x', ret); 
   }
}
8

A common cause of this sort of error is a variable (called "test" or "Test") hiding the static class method reference Test.setMock. But if you have posted the complete source code it would not be that.

Saving this first:

@isTest
global class WebServiceMockImpl implements WebServiceMock {
   global void doInvoke(
           Object stub,
           Object request,
           Map<String, Object> response,
           String endpoint,
           String soapAction,
           String requestName,
           String responseNS,
           String responseName,
           String responseType) {
   }
}

and then this:

@isTest
private class WebSvcCalloutTest {
    @isTest static void testEchoString() {
        Account a = new Account(name='Tester');
        insert a;              
        // This causes a fake response to be generated
        Test.setMock(WebServiceMock.class, new WebServiceMockImpl());
    }
}

compiles fine in my org even taking the "Salesforce.com API" version back to 18.0.

I suggest to track down the cause you simplify until it compiles and then add code back in until it doesn't.

PS

The issue was shadowing, but probably by a separate class not a variable in the class (based on the comments below). Adding the system namespace prefix:

System.Test.setMock(...);

works around both types of shadowing.

| improve this answer | |
  • Thanks @Keith. You had given a very good suggestions stating debugging piece by piece...Let me try this. – Bforce Mar 31 '14 at 17:39
  • still i am getting the same issue the same classes given in the above link works fine in another developer org (the new one which i created to test this issue), but bombing out in my current developer edition. i changed the versions back and forth, still it complains the same error. i do not know why this is happening? Any thoughts? – Bforce Apr 4 '14 at 13:19
  • 1
    @baskaran Do you have a local class called Test in your current developer edition? This error looks like some sort of hiding problem where instead of "Test" referencing the Salesforce class something else is being referenced. Add the namespace i.e. try "System.Test.setMock(...)" - that should avoid the hiding problem. – Keith C Apr 4 '14 at 13:33
  • Keith, it works this time after i added the namespace. Should be some issue in my objects that something might have named "Test"... Thank you for helping out. – Bforce Apr 4 '14 at 13:40
  • Keith, you are 110% right. i do not how that class came with the name test.cls and it has a comment on the top "Generated by AdminBooster". I havent created it either. Is that spam or something? On seeing i instantly deleted it with an anger that it wasted my time for more than 2 to 3 hrs...Thanks again!! – Bforce Apr 4 '14 at 18:20
0

Replace test.setMock(...,..) method with Static.Test.setMock(...,...)

| improve this answer | |
  • Did you mean System.Test.setMock()? – martin Jul 14 '17 at 6:52
-1

I think u have already created one apex class with name "test".That is overriding this.Please check it and delete if any. The below link will help you. http://salesforceglobe4u.blogspot.com/2016/04/error-compile-error-method-does-not.html

| improve this answer | |
  • Welcome to SFSE Suneel. You should post relevant content from the link here directly as link-only answers tend to become useless over time. – Matt Lacey Apr 22 '16 at 3:04

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.