---
schema_version: "1"
id: d90ed6f67c0519cad62ff30cd59b359789c2bbdb8ccae15165b8e6cd67253167
title: AsyncCondition Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_interface_TxnSecurity_AsyncCondition_interface.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_TxnSecurity_AsyncCondition_interface.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: fbe804ffd795c3bae2dff1394bfb2b84f53b0962904ea85213a92ab00b37ad55
description: Allows an implementing class to make asynchronous Apex calls. This interface is used only for transaction security Apex policies created in Real-Time Event Monitoring.
---
# AsyncCondition Interface

Allows an implementing class to make asynchronous Apex calls. This interface is used only for transaction security Apex policies created in Real-Time Event Monitoring.

## Namespace

[TxnSecurity](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_TxnSecurity.htm "The TxnSecurity namespace provides an interface used for transaction security.")

## Usage

If you make an [Asynchronous Apex](https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex "HTML (New Window)") call in the class that implements your transaction security policy condition, the class must implement the TxnSecurity.AsyncCondition interface in addition to TxnSecurity.EventCondition. Use Asynchronous Apex instead of Apex callouts and DML statements, neither of which is allowed in transaction security Apex policies.

Apex offers multiple ways to run your Apex code asynchronously and all are supported in the TxnSecurity.AsyncCondition interface.

This interface has no methods.

- **[AsyncCondition Example Implementation](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_TxnSecurity_AsyncCondition_interface.htm#apex_interface_TxnSecurity_AsyncCondition_Example)**

#### See Also

- [_Apex Developer Guide_: Asynchronous Apex](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_async_overview.htm)

## AsyncCondition Example Implementation

Here’s an example implementation of the TxnSecurity.AsyncCondition interface. The transaction security policy triggers when a user logs in. In the example, ExternalValidation\_\_c is a custom object that contains information from an external validation system. The result of the SOQL query on ExternalValidation\_\_c determines whether to block the user from logging in. The policy then queues the CalloutToExternalValidator class for asynchronous execution. When it executes, the CalloutToExternalValidator class makes an external call to the validation system to update it with information about this log in event. Because CalloutToExternalValidator is triggered by Asynchronous Apex, you must implement the TxnSecurity.AsyncCondition interface in the ExternallyValidatedLoginCondition Apex class along with the usual TxnSecurity.EventCondition interface.

global class ExternallyValidatedLoginCondition implements TxnSecurity.EventCondition, TxnSecurity.AsyncCondition {
    public boolean evaluate(SObject event) {
        LoginEvent loginEvent = (LoginEvent) event;
        Boolean userBlocked = \[select blocked from ExternalValidation\_\_c where loginId = loginEvent.UserId\]\[0\].Blocked;
 
        System.enqueueJob(new CalloutToExternalValidator(loginEvent.SourceIp, loginEvent.LoginUrl));
        return userBlocked;
    }
}
 
public class CalloutToExternalValidator implements Queueable {
    private String sourceIp;
    private String loginUrl;
 
    public CalloutToExternalValidator(String sourceIp, String loginUrl) {
        this.sourceIp = sourceIp;
        this.loginUrl = loginUrl;
    }
 
    public void execute(QueueableContext context) {
        // callout to external validation service
        // pass sourceIp, loginUrl
                
        // update ExternalValidation\_\_c
    }
}