Execute Apex Action

Call Apex Action allows to call KanBan API or Custom Apex class.

  • Add an action with the type Call Apex (1). See more info about creating Actions in Working with Actions article.

  • Check the KanBan API checkbox (2).

  • Select the API Class Name (3).

  • Select the API Method Name (4)

  • Provide API Parameters (5).

You can use Static values, Merge Fields or Formulas to populate parameters.

See more info on Merge Fields and Formulas at Working with Context objects and Working with Functions

  • Variable Name (6) - specify name of the variable that will contain action result.

  • Execute in background (7) - select it if you need to execute "Call Apex" action in other context than current user operation.

  • Check "Wait for result" checkbox (8) if you need to receive action execution result in order to work with it (e.g., when using action in action group or getting data from external resource).

  • Populate "With gap" field (9) to set time system will wait before execute action (in minutes).

Using Custom apex

  • Uncheck KanBan API checkbox (10).

  • Select the Class Name in the drop-down. If you don't see your class in the drop-down, use Filter option (11).

  • Enter Parameters in a JSON format (12).

Apex class should inherit FLX_KB.KanBanInterfaces.CallApexActionInterface

Below is an example of an apex class that is triggered by Kanban action.

It will send an email with Account name if passed parameter 'function' equals 'customFunction'.

public with sharing class FLX_ApexActions implements FLX_KB.KanBanInterfaces.CallApexActionInterface {
    public Object executeCallApex(FLX_KB__KanBan_History__c kanbanHistory, sObject record, Object parameters){
        Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped((String)parameters);
        if(params.get('function') == 'customFunction') 
            runCustomFunction(params.get('accountName'));
        return null;
    }

    private void runCustomFunction(Object recordName) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new List<String>{UserInfo.getUserEmail()});
        mail.setSubject('An email from FLX_ApexActions class');
        mail.setPlainTextBody('This email has been sent through custom FLX_ApexActions class. Account Name is ' + recordName);
        Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{mail});
    }
}
  • Variable Name (13) - specify name of the variable that will contain action result

  • Execute in background (14) - select it if you need to execute "Call Apex" action in other context than current user operation.

  • Check "Wait for result" checkbox (15) if you need to receive action execution result in order to work with it (e.g., when using action in action group or getting data from external resource).

  • Populate "With gap" field (16) to set a wait time which action will be executed after.

See more information at Execute in background option.

  • Save the action.

Now you can call it from Kanban and other places.

Last updated