Defining Reusable Behavior with an Object Function

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 code related to the same object.

In addition, you can invoke them using a button or link in the user interface. The supported return types and optional parameter types are the same as for global functions (described above).

For example, you might define the following updateOpenTroubleTicketCount() object function on a Contact custom object. It begins by calling the logStart() global function above to log a diagnostic message in a standard format to signal the beginning of a block of custom Groovy script. It calls the newView() built-in function (described in Accessing the View Object for Programmatic Access to Business Objects) to access the view object for programmatic access of trouble tickets, then appends a view criteria to find trouble tickets related to the current contact's id and having either 'Working' or 'Waiting' as their current status. Finally, it calls getEstimatedRowCount() to retrieve the count of trouble tickets that qualify for the filter criteria. Finally, if the new count is different from the existing value of the OpenTroubleTickets_c field, it updates this fields value to be the new count computed.

  • Function Name: updateOpenTroubleTicketCount

  • Return Type: void

  • Parameters: None

Function Definition

adf.util.logStart('updateOpenTroubleTicketCount')
// Access the view object for TroubleTicket programmatic access
def tickets = newView('TroubleTicket_c')
tickets.appendViewCriteria("""
Contact_Id_c = ${Id} and Status_c in ('Working','Waiting')
"""
// Update OpenTroubleTickets field value
def newCount = tickets.getEstimatedRowCount()
if (OpenTroubleTickets_c != newCount) {
  OpenTroubleTickets_c = newCount
}