Newer Version Available
Apex Trigger Example
Using an Apex Change Event Trigger to Predict Account Status
Because Apex change event triggers run asynchronously, they typically contain time-intensive processes that run after the database transaction is completed. This trigger example covers a more common real-world scenario than the trigger given in the quick start. It captures case changes and predicts the account trust status using an Apex class. The prediction is based on counting the account cases and checking case fields. In other scenarios, you might have complex prediction algorithms that are more resource intensive.
- A platform event named Red_Account__e with two fields: Account_Id__c of type Text and Rating__c of type Text
- The SLAViolation__c custom field on the Case object of type Picklist with values Yes and No
The RedAccountPredictor class performs the prediction of the account trust level. The first method that the trigger calls is predictForCases, which calls other methods in this class. The method returns a map of account ID to a Boolean value for account status.