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

How to create function/method in Apex class

How can I create and call a function in an Apex class that will return a value? I have managed to create a void method that doesn't return, but I need to return a value.

Please review the Apex language reference guide: as well as the Apex wiki site:

To answer your question, I've included the following example:

public class foo {
string str_foo;
    public string retfoo(String foo){
    str_foo = 'method retfoo is returning this value:  '+foo;
    return str_foo;

--- you can invoke this through the following script:
foo f = new foo();
f.retfoo('I am returning something');
wat wud the type of the method be if I am trying to build an update method?