SK SKYVVA Documentation

5.1 Using Salesforce CDC change event

Learning Objectives

A Change Data Capture event, or change event, is a notification that Salesforce sends when a change to a Salesforce record occurs as part of a Create, update, delete, or undelete operation. User has to create Account in SalesForce, it should trigger an event and send this Account Information to MS SQL Server DB of our organization. Once it's inserted in our SQL DB, it will create particular AccountID and give it back to SalesForce. The notification includes all new and changed fields and header fields that contain information about the change.

Introduction

The reason users need to accomplice this is our Account creation process used to start from Our own SKYVVA product so it was creating AccountID (Auto Generated) from DB and used from Primary identification for Account across the system. Now we want to create Account from SalesForce but need to keep AccountId generated from SQL DB. For example, header fields indicate the type of change that triggered the event and the origin of the change. Change events support all custom objects and a subset of standard objects.

[su_box title="Note" box_color="#2a8af0" title_color="#000000"]User have to click on link below through which user get configuration about, How to Consume the change events using an apex trigger.[/su_box]

So here we will learn How to Consume the change events using an apex trigger and do local action e.g. update an account:-

How to use it? Follow the given steps:- Step 1:- Subscribing to platform events:-

  1. From Setup, enter Debug Logs in the Quick Find box, then click Debug Logs.
  2. Click New.
  3. For Traced Entity Type, select Automated Process.
  4. Select the time period to collect logs and the debug level.
  5. Click on Save.
[su_box title="Note" box_color="#2a8af0" title_color="#000000"] Using the Event PlatForm for use the Salesforce CDC change event to send data out with the SKYVVA API ,The user type is  Automated Process.[/su_box] Step 2:-  Select Object for Change data capture:-
  1. From Setup, enter Change data capture in the Quick Find box.
  2. Select-Object.
  1. Save it.
Step 4:- Create an Apex trigger:-

  1. Click on the Submit button to generate a header script.
  2. After clicking on the submit button.
  3. We will add the code as shown in the picture given below.

We can use this code:- [aux_code language="javascript" theme="tomorrow" title="" extra_classes=""]trigger trgTestCDC on AccountChangeEvent (after insert) { List lstId = new List(); for (AccountChangeEvent event : Trigger.New) { EventBus.ChangeEventHeader header = event.ChangeEventHeader; System.debug('Received change event for ' + header.entityName + ' for the ' + header.changeType + ' operation.'); System.debug('RecordIds: ' + header.recordIds); System.debug('Account Name: ' + event.Name); System.debug('Account Phone: ' + event.Phone); if ( header.changetype == 'UPDATE') { lstId.addAll(header.recordIds); } } }[/aux_code]

Check the result on Debug logs:-

  1. From Setup, enter Debug Logs in the Quick Find box, then click Debug Logs.
  2. We can check result in debug logs.
Now you might be thinking why our chapter name is "How to use the Salesforce CDC change event to send data out with the SKYVVA API?" So here is the reason. The salesforce CDC change event to send data out with the SKYVVA API means, that we are using a combination of the real-time capability of salesforce change data capture and callout capability of SKYVVA. The callout capability of SKYVVA is best as we have different adapters that connect to many external systems for this our user doesn't need a programmer. This is the benefit of using SKYVVA invoke Callout2().

We provide these two modes to our user:-

When to use which mode:-

So here we will learn how to consume the event using an apex trigger and sending out data using Invoke callout2.

How to use it? Pre-requisite:-

Follow the given steps:- Step 1:- Subscribing to platform events:-

  1. From Setup, enter Debug Logs in the Quick Find box, then click Debug Logs.
  2. Click New.
  3. For Traced Entity Type, select Automated Process.
  4. Select the time period to collect logs and the debug level.
  5. Click on Save.
[su_box title="Note" box_color="#2a8af0" title_color="#000000"] Using the Event PlatForm for use the Salesforce CDC change event to send data out with the SKYVVA API ,The user type is  Automated Process.[/su_box] Step 2:- Register Licence key for Automated Process user:-
  1. From Setup, enter custom settings in the Quick Find box.
  1. Click on the Manage option.

  1. Click on the "NEW" button at the top.

  1. Enter the SKYVVA license key in the value block.
  1. Save it.

Step 3:-  Select Object for Change data capture:-

  1. From Setup, enter Change data capture in the Quick Find box.
  2. Select-Object.

  1. Save it.

Step 4:- Create an Apex trigger:-

  1. Click on the Submit button to generate a header script.
  2. After clicking on the submit button.
  3. It will show the screen as shown in this picture given below.

Step 5:-  Generate Trigger script by following steps given below:-

  1. Select and copy the generated script and paste it in the apex trigger which we created in step 4.
  2. Do it as shown in the picture given below.

[su_box title="Note" box_color="#2a8af0" title_color="#000000"]For trigger after delete it is working when query selection with keyword "ALL ROWS". E.g SELECT BillingCity,BillingCountry,Name,Id,Description From Account ALL ROWS[/su_box]

When to use which mode:-

Now Users can be configured how SKYVVA Change Events to synchronize changes to the Salesforce records in your SQL server Db Management system. SKYVVA can Change/Update events the same way you subscribe to other events. Connect to Server

Now go to Salesforce Click on Adapter Tab

Now go to the Agent and Select your Integration which you just created

Now see Interface Source Definition

Go to Salesforce Org and click on Message Monitoring

Open SQL Server Now

Now Change/Update on Salesforce Org.

Open SQL Server Now

Open this article in the interactive viewer →