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
Bernard FarrellBernard Farrell 

What does 'Non-void method might not return a value' mean?

I'm trying to call an external web service from Apex.

The web service call returns an array of objects. So the generated Apex definition for the call is something like:

public class testWsdl {

    public class CalculationPort {

        public testWsdl.ComputedType[] calculate(DateTime start,DateTime end_x,DateTime now)
        ...

When I invoke it, I use the following code (declarations omitted for clarity):

  testWsdl.CalculationPort stub = new testWsdl.CalculationPort();
  testWsdl.ComputedType[] results = stub.calculate( start, end_x, now);

I get the following error on the second line:
  Non-void method might not return a value

I have no idea what this means. I've also tried the following code:
  testWsdl.ComputedType[] results = testWsdl.ComputedType[0];
  results = stub.calculate( start, end_x, now);

And I get exactly the same error.

I think I understand what the error means, that the variable results may be null after the call has completed.

My question is, how do I get rid of the error?

Bernard FarrellBernard Farrell
We figured the problem out and I wanted to share it in case someone else comes across it.

The method that I was invoking was the last executable statement in a String function that I had defined.

I'd forgotten to put a return statement in the method. The error that was reported should have said something like "String function xxx does not contain a return value".

Because it didn't give the name of the method causing the error I was looking in the wrong place.
Richard VanhookRichard Vanhook
Bernard, thanks for the post - I had a similar issue.  The error message is pretty much worthless.
MicahHoover.ax1233MicahHoover.ax1233

I got the same error, and it was badly worded for me to.

 

I thought there was an issue with a function that got called in the code block, but it was actually the function defined in the code block.

 

In any case it should point to the beginning or end of the method.