How to exit an apex function?

Yogini Mane picture Yogini Mane · Feb 13, 2013 · Viewed 11.8k times · Source

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?

Answer

Eric Sexton picture Eric Sexton · Feb 13, 2013

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

public void doNothing() {
     return;
}