How to register custom Function

The Work-Relay application allows you define your own functions. 

Once custom formula is developed it needs to be registered in Work Relay:

  • switch to the classic version of Salesforce
  • go to the Settings -> General Settings -> "Custom Functions" section
  • click "Add New" button (1)

You can configure the custom function properties:

  • Name  - custom function name. Should not contain spaces and special symbols. Preferable the upper case.
    Example: CALCULATETOTAL
  • Handler Class - apex class name that implements WR_BPM.FunctionInterface interface and stores function code.
    Example: MyCustomFunctionClass
  • Category - category to put the formula in.
  • Definition - definition of the formula that will be shown as a formula example expression.
    Example: CALCULATETOTAL(column_id)

After that you will be able to find this function in all application formula builders and use it.

The example of apex class that returns image URL by image ID or by image name:

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.