Overview of Object Functions

Object functions are useful for code that encapsulates business logic specific to a given object. You can call object functions by name from any other script related to the same object.

You can also call them using a button or link in the user interface. Object functions can be reused in multiple contexts. For example, you can reuse an object function inside a trigger or validation rule. You can also use an object function asynchronously by using a scheduled process, or by using it inside an object workflow's Groovy script action.

Let's say you want to make an asynchronous call to an external web service so that you don't have to wait for a long-running web service to complete. You can:

  • Call the web service using an object function at a scheduled time using the Scheduled Processes tool. You can process a set of records on a daily or weekly basis, asynchronously, when users don't need to see immediate feedback in the user interface.

    See the Using Object Functions for Scheduled Processes section in this topic.

  • Call the web service using an object function from an object workflow's Groovy script action. Object workflows are also executed asynchronously and provide additional functionality, such as letting you set the conditions for when the workflow is triggered.

    See How Object Workflows and Groovy Scripts Work Together in the Related Topics.

Note: You can't update records by calling object functions using the setAttribute() through the RESTful service due to the lack of transaction control. Instead, create a new custom field and call the object function from its field trigger, and then update this field using REST.

You can optionally define object functions to return values. You can also specify typed parameters, which the caller will be required to provide values for, when the function is invoked. The supported return types and optional parameter types are the same as for global functions. However, scheduled processes only support object functions that have no parameters and that have String as the return type, if the function is defined to return values. So, if you're defining an object function to be used in a scheduled process, ensure that it has no parameters defined, and if you're defining the function to return a value, ensure that its return type is String.

For more information on object functions, see the Groovy Scripting Reference guide.