How to Register a Custom Function
Work-Relay Admins may define Custom Functions for use within the Work-Relay application when more advanced configuration is required. Each Custom Function is implemented by an Apex Class, which defines the Custom Function logic. For this reason, the desired Apex Class must be created prior to creating a Custom Function.
To create a Custom Function, navigate to Settings > Utilities > Custom Functions, then click the "+" button (1).
Configure the following properties:
-
Name (2) - The Name of the Custom Function, as it will be displayed in the Context Object Items picklist for the $Functions Context Object when defining a Formula within various Work-Relay configuration screens (as shown in the example above). This value should not contain spaces and special symbols, and it is recommended to use all uppercase letters. (Example:
SOBJECTTYPE
) -
Handler Class (3) - The Apex Class that implements the
WR_BPM.FunctionInterface
interface and stores the custom logic. (Example:AbstractControllerClass
) - Category (4) - The category into which the Custom Function will be organized in the Context Object Items picklist.
-
Definition (5) - The definition of the function, which will populate as the Merge Field value, which may be copied/inserted into the Formula that is being constructed. (Example:
SOBJECTTYPE(id)
)
Be sure to Save all changes.
An example of an Apex Class (which could be called by a Custom Function) that returns an image URL by image ID or by image name is provided below:
public with sharing class WorkRelayApexFunctions implements WR_BPM.FunctionInterface
{
public static Object executeFunction(String name, List<Object> parameters, Map<String,Object> context)
{
if(name == 'GETIMAGEURL' && parameters.size() > 0)
{
String image = (String)parameters[0];
if(image instanceOf Id)
return URL.getSalesforceBaseUrl().toExternalForm() + '/servlet/servlet.ImageServer?id=' + image + '&oid=' + UserInfo.getOrganizationId();
else
{
List<Document> docs = [SELECT Id FROM Document WHERE Name = :image];
return docs.size() > 0 ? URL.getSalesforceBaseUrl().toExternalForm() + '/servlet/servlet.ImageServer?id=' + docs[0].Id + '&oid=' + UserInfo.getOrganizationId() : null;
}
}
else
{
... logic here ...
}
}
}
0 Comments
Add your comment