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
StormConsultingStormConsulting 

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.

Cheers
tmatthiesentmatthiesen
Please review the Apex language reference guide: http://www.salesforce.com/us/developer/docs/apexcode/index.htm as well as the Apex wiki site: http://wiki.apexdevnet.com/index.php/Apex_and_Visualforce

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');
system.debug(f);
Mr.BrooksMr.Brooks
wat wud the type of the method be if I am trying to build an update method?