# 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](https://flexikanban.screenstepslive.com/admin/v2/internal_links/1641589?type=article\&site_id=24620) article.

![](https://media.screensteps.com/image_assets/assets/007/223/352/medium/d43e9a04-94ce-4003-9e53-a32bef2a04bc.png)[Using KanBan API](https://flexikanban.screenstepslive.com/admin/v2/sites/24620/toc/manuals/115345/chapters/402870?showArticle=1641614)

* Check the **KanBan API** checkbox (2).
* Select the **API Class Name** (3).
* Select the API Method Name (4)
* Provide **API Parameters** (5).

![](https://media.screensteps.com/image_assets/assets/007/223/355/medium/ebfe3fd2-e9c5-4781-9965-45d78c645e7f.png)

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](https://flexikanban.screenstepslive.com/admin/v2/internal_links/1641592?type=article\&site_id=24620) and [Working with Functions](https://flexikanban.screenstepslive.com/admin/v2/internal_links/1641591?type=article\&site_id=24620)

* **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](https://flexikanban.screenstepslive.com/admin/v2/sites/24620/toc/manuals/115345/chapters/402870?showArticle=1641614)

* 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).

![](https://media.screensteps.com/image_assets/assets/007/366/690/medium/579771d7-516b-457e-bc63-56cf8ce064c2.png)

Apex class should inherit FLX\_KB.KanBanInterfaces.CallApexActionInterface

Below is an example of an apex class that is triggered by Kanban action.&#x20;

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](https://flexikanban.screenstepslive.com/admin/v2/internal_links/1641667?type=article\&site_id=24620).

* Save the action.

Now you can call it from Kanban and other places.
