---
schema_version: "1"
id: 82312f1ef54fdd5287bf168c60a976bcb5fb68cc9cc9a3476050a7c91c441983
title: Available For Flow Actions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lightning-base-components/lightning-design-system/guides/aura/components/lightning/availableForFlowActions/aura-available-for-flow-actions.md
canonical_url: https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura-available-for-flow-actions.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 1ba95d73c2ab9b3c5ca26527ee008bd9613cea6014b0d1bb0bf799474a1ebf8f
products:
  - Lightning Component Reference
---
# Available For Flow Actions

**`lightning:availableForFlowActions`**

Enables a component's controller to be used as an action in a flow.

**For Use In**

Lightning Experience

::::::tabset{tabs='[ "Develop", "Specifications"]'}

:::::tab

Add the `lightning:availableForFlowActions` interface to a Lightning component to make it available as a flow action. When a component is executed as a flow action, the flow calls the `invoke` method in the client-side controller. Flows that include Lightning components are supported only in Lightning runtime.

Lightning components that implement `lightning:availableForFlowActions` are available as Local Action elements in the Cloud Flow Designer. If an attribute is declared in the component's design resource, flow admins can pass values between that attribute and the flow when they configure the Local Action element.

To run your code asynchronously, for example because you're making an XML HTTP request (XHR), return a Promise.

When the method finishes or the Promise is settled, control is returned back to the flow.

- Asynchronous Code: When a Promise is fulfilled, the next element in the flow is executed. When a Promise is rejected or times out, the flow takes the Local Action element's fault connector and sets `$Flow.FaultMessage` to the error message. By default, the error message is "An error occurred when the flow tried to execute the c:myComponent component.". To customize the error message, return it as an error in the `reject()` call. When a Promise times out, it returns control to the flow, but it doesn't cancel the original request. For example, if the request fires a `force:showToast` event after a delay, the event still fires even after the promise times out. To abort a Promise, use the `cancelToken` attribute provided by the interface.

- Synchronous Code: When the method finishes, the next element in the flow is executed.

This example shows the markup required to add the `lightning:availableForFlowActions` interface to a Lightning component.

```html
<aura:component implements="lightning:availableForFlowActions">
  // declare attributes here
</aura:component>
```

Here's an example of an asynchronous client-side controller. The `invoke` method returns a Promise. When the method has done all it needs to do, it completes the call. If the request is successful, the method uses `resolve()` to execute the next element in the flow after this action. Otherwise, it uses `reject()` to take the Local Action element's fault connector and sets `$Flow.FaultMessage` to "My error message". If the request takes too long, it uses `cancelToken.promise.then` to abort the request.

```javascript
/** Asynchronous Client-Side Controller **/
({
    invoke : function(component, event, helper) {
       var cancelToken = event.getParam("arguments").cancelToken;

       return new Promise(function(resolve, reject) {
          var xhttp = new XMLHttpRequest();

          // Do something, like get data from
          // a database behind your firewall
          xhttp.onreadystatechange = $A.getCallback(function() {
              if (/* request was successful */) {
                // Complete the call and return to the flow
                resolve();
              } else {
                reject(new Error("My error message"));
              }
          });

          // Gracefully abort the Promise if it times out
          cancelToken.promise.then(function(error) {
              xhttp.abort();
              reject(error);
          });
       });
    }
})


```

Here's an example of a synchronous client-side controller. When the `invoke` method finishes, control returns to the flow.

```javascript
/** Synchronous Client-Side Controller **/
({
  invoke: function (component, event, helper) {
    // Do something, like open another browser tab
    // with a specified URL
  },
});
```

For more information, see [Create Flow Actions By Using Lightning Components](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_flow_actions.htm).

## Methods

This interface requires your component to implement the following method.

`invoke(component, event, helper)`: Called when a flow executes the component as a local action. To handle asynchronous calls, construct a Promise in this method.

- `cancelToken` (Object): A token that you can use to gracefully abort a Promise. When the Promise times out, `cancelToken.requested` is set to `true` and `cancelToken.promise` is resolved with a timeout Error object.


:::::

:::::tab
![No specifications to show](https://developer.salesforce.com/media/no-specs.png)

:::::

::::::
