Change Data Capture and Asynchronous Apex Trigger
Author
January 28, 2021
When we insert and do changes on SObject records and save them on Salesforce, platform start a series of calculations called apex transaction. Sometime due to complex calculations, it takes a lot of time to complete a transaction which in results CPU time out exception. You can reduce these transaction time and limit constraints by decoupling resource-intensive, non-transactional logic from database and run asynchronously.
This can be achieved by this Salesforce feature change data capture and a new enhancement in Summer’19 release, asynchronous apex trigger.
What is Change Data Capture and Asynchronous Apex Trigger?
Change Data Capture is a streaming product on lightning platform that enables you to integrate your Salesforce data to external system. This feature enables you to replicate data changes to external systems. CDC publishes the events which stores deltas of Salesforce data for new and changed records. This feature can be enabled for some standard objects and all custom objects. Once it is enabled, it starts publishes the events whenever record create, update, delete or undelete. The published event contains metadata information of record and changed field values.
Asynchronous trigger is a change event trigger which run asynchronously after a database transaction is completed. The async execution of change event trigger makes them ideal for processing resource-intensive business logic in separate transaction from database transaction.
How does Change Data Capture and Asynchronous Apex Trigger?
Whenever a record is created, updated, deleted or undeleted then CDC will publish events. And trigger will process those events. These triggers are after-insert trigger and run on change event objects instead of SObjects.
Let me explain it by an example.
By creating trigger on Opportunity Change Event object named as Opportunity Change Event Trigger. You can create trigger by using CLI form VS code terminal by this command:
sfdx force: apex: trigger:create -n Opportunity Change Event Trigger -s Opportunity Change Event -e ‘after insert’ -d ‘force-app/main/default/triggers’.
From the Developer Console by selecting File→New→ Apex Trigger and then OpportunityChangeEvent for the sObject.
Whenever opportunity record is created, updated, deleted or undeleted, change data capture will fire events which will run this trigger before that we must enable CDC feature on opportunity object. So what trigger is doing whenever saved record field isWon is true, creating a follow up task. Below are code snippets.
Considerations:
- Async triggers are ‘after-insert’ triggers run only when changes are committed to database.
- Multiple async trigger run works on same objects. Each have their own limits.
- These triggers run asynchronously but have synchronous limits like no extra heap size, CPU time and SOQL query limit.
- Like object trigger, these are also not able to make call to external API.
- Trigger.new contains max of 2000 published events. So, at time it can process 2000 events.
- Set Automation Process as trace entity for debug logs of async triggers.
- There is no limit concept for CDC.
- Maximum 5 objects can be enabled for CDC feature for dev orgs, it can be extended by purchasing CDC license.
- CDC is supported for some of standard objects and all custom objects.
Use Cases:
- For Proper decoupling and clean architecture, async trigger is better option than other async processes.
- For every scenario where you need to break the transaction, like you want to separate database processes and business calculations.
Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”
Recent Posts
-
Leveraging AI to Enhance Sales Effectiveness13 Mar 2025 Use-case
-
Revolutionizing Manufacturing with AI: Predictive Maintenance, Supply Chain Optimization, and More11 Mar 2025 E-Book
-
NetSuite for Manufacturing: Streamlining Operations and Solving Key Challenges07 Mar 2025 Blog
-
How to Build Your First Agent in Salesforce Agentforce24 Feb 2025 Blog
-
ERP vs Salesforce Revenue Cloud: Which One is Right for Your Business?24 Feb 2025 E-Book
-
Revolutionizing Manufacturing with Salesforce: A Playbook for Efficiency & Growth18 Feb 2025 E-Book
-
Salesforce 2025 Game-Changing Trends You Need to Know28 Jan 2025 Blog
-
Agentforce 2.0: Everything You Need to Know About the Latest Update22 Jan 2025 Blog
-
The Ultimate Guide to NetSuite Development: Tools and Techniques10 Jan 2025 Blog
-
How Salesforce Nonprofit Cloud Transforms Fundraising Strategies10 Jan 2025 Blog
-
The Impact of Salesforce Development Partners on Small and Medium Businesses08 Jan 2025 Blog
-
Key Questions to Ask When Hiring a NetSuite Development Partner08 Jan 2025 Blog
-
Salesforce Agentforce Demystified: Your Essential Guide08 Jan 2025 Blog
-
Salesforce and NetSuite Integration: Driving Business Efficiency with Precision06 Jan 2025 Blog
-
Everest Group has positioned Mirketa as an Aspirant in the report24 Dec 2024 Press Release
-
Salesforce Einstein20 Dec 2024 E-Book
-
Order to Cash Cycle with NetSuite20 Dec 2024 E-Book
-
Empower Your Marketing Strategy with Salesforce Marketing Cloud's Automation Studio Activities13 Dec 2024 Blog
-
Salesforce CPQ for Subscription-based Businesses10 Dec 2024 Blog
-
Unleashing the Magic of Einstein Prediction Builder10 Dec 2024 Blog
Categories
Featured by



