1

I am at a loss as to why I am running into issues here. I am trying to simply make a call to a method within a class, from a web service method.

The error I continue to get is:

Save error: Non-void method might not return a value or might have statement after a return statement.

I am calling this through Execute Enonymous:

TestClass.callWebService();

global with sharing class TestClass
{

    void testing()
    {


    }

    WebService static void callWebService()
    {    
        testing(); // doesn't work
        //this.testing() also doesn't work
        //TestClass.test() also doesn't work
    }           
}
3

You can only call static methods from within static methods. You cannot call instance methods.

Works

static void doStuff() { /* logic */ }
webservice static void callWebService()
{
    doStuff();
}

Fails

void doStuff() { /* logic */ }
webservice static void callWebService()
{
    doStuff();
}
  • Thanks, that's what I was assuming. I found an issue with the code I had (I tried to clean it up for a more simple demonstration), and apparently I deleted the return line at the very end of the web service method.. it wasn't void in my code, so I think the error was telling me that is where the issue was.. but Salesforce and its generic error messages.. – tchock Oct 25 '16 at 23:18

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.