Asynchronous Trigger in Salesforce using Change Data Capture

Asynchronous Trigger in Salesforce using Change Data Capture

1. Setup/Enable Change Data Capture.

In this example, I have enabled Case object.

2. Create a Trigger.

Sample Trigger:

trigger CaseChangeEventTrigger on CaseChangeEvent ( after insert ) {
    
    for ( CaseChangeEvent event : Trigger.New ) {
      
        System.debug( 'Event is ' + event );
        
   }

}

3. Setup Debug Logs for Automated Process user to check the logs.

Test Class for Change Data Capture Trigger:

@isTest
private class CaseChangeEventTriggerTest {
    
    static testMethod void testCDC() {
        
        Test.enableChangeDataCapture();
        insert new Case(
            Subject = 'Testing',
            Origin = 'Phone'
        );
        Test.getEventBus().deliver();
        
    }
    
}

Leave a Reply