+ 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: 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');
wat wud the type of the method be if I am trying to build an update method?