Subscribe to Change Events Using an Apex Trigger | Change Data Capture Basics

Описание к видео Subscribe to Change Events Using an Apex Trigger | Change Data Capture Basics

#salesforce
#trailhead
#salestraining

Change Data Capture Basics

Asynchronous Apex Triggers for Change Events
Write a Change Event Trigger
Create a change event trigger that captures changes on opportunities and creates a follow-up task for opportunities whose stage is set to 'Closed Won'.
Create an Apex trigger modeled after the EmployeeChangeTrigger example trigger:
Name: OpportunityChangeTrigger
Object: OpportunityChangeEvent
Copy the body of the EmployeeChangeTrigger example trigger. Delete everything after the if statement for the header, starting with the System.debug statements.
Modify the for loop so it iterates over every received OpportunityChangeEvent. For each event, if the header changeType field is 'UPDATE', check if event.isWon field is equal to true. You will end up with the following if statement:
if ((header.changetype=='UPDATE') && (event.isWon==true)) { // Create a task }
Inside the new if statement block, add these lines to create a task.
Task tk = new Task();
tk.Subject = 'Follow up on won opportunities: ' + header.recordIds;
tk.OwnerId = header.CommitUser;
tasks.add(tk);
Insert the task list after the end of the for loop.
if (tasks.size() 0) {
insert tasks;
}

Комментарии

Информация по комментариям в разработке