8
votes

I have an apex function which has a void return type. I want to exit the function at a specific position. Is this possible in apex without changing return type pagereference?

2

2 Answers

17
votes

In apex, the return keyword signals to immediately stop processing statements in that function.

public void doNothing() {
     return;
}
0
votes

I'm not sure that I correctly understood your question (more detailed description will be useful), but it seems that you can use a return statement by the following way:

public PageReference method() {
    //some your code ....
    if (some specific condition) { 
        return null;
    }

    PageReference pageRef = new PageReference('someURL');
    return pageRef;
}

Please show your code for a more target help