Transaction Security in Salesforce

Transaction Security is a feature that monitors Salesforce events in real time and applies actions and notifications based on rules you create. These rules, or policies, are applied against events in your org. (In the earlier example, our policy was to have no more than three active sessions per user.) You create policies for certain event combinations, and specify actions to take when those events occur.

1. Go to Transaction Security.


2. Enable Transaction Security Policies.


3. Create New Custom Transaction Security Policy.

Example:

Below New Custom Transaction Security Policy will send an email if any user logs in from Safari browser.


Apex class generated as part of this is below:

global class AvoidSafariBrowserPolicyCondition implements TxnSecurity.PolicyCondition {
    
    public boolean evaluate(TxnSecurity.Event e) {
        LoginHistory eObj = [SELECT ApiType FROM LoginHistory WHERE Id = :e.data.get('LoginHistoryId')];
        if(eObj.ApiType == 'Safari') {
            return true;
        }        
        return false; 
    }
    
}

Cheers!!!

No comments:

Post a Comment