Step 5: Subscribe to Change Events
Use the ProcessChangeEventHeader.java
example to subscribe to change events and perform bitmap field expansion. ProcessChangeEventHeader.java
expands the bitmap fields in change events, such as the changedFields
field, into its component fields.
Change event headers are described in ChangeEventHeader Fields in the Change Data Capture Developer Guide.
Prerequisites
- Because the ProcessChangeEventHeader example subscribes to changes for Opportunity, select Opportunity for change data capture in Setup. For more information, see Select Objects for Change Notifications in the User Interface in the Change Data Capture Developer Guide.
-
In your
pub-sub-api
folder, navigate tojava/src/main/resources
and open thearguments.yaml
file. Provide the change event channel as theTOPIC
argument.TOPIC: /data/OpportunityChangeEvent
-
In a Terminal window, navigate to the
java
folder. -
To run the example, from the top-level
java
folder, enter:./run.sh processchangeeventheader.ProcessChangeEventHeader
- The example subscribes to the
/data/OpportunityChangeEvent
channel and captures any new or changed Opportunity records.
- The example subscribes to the
-
The example prints out logging information similar to:
-
In Salesforce, create an opportunity record. The change event is received and printed. For example:
-
Update the opportunity record. For example, select a
Type
ofNew Customer
. The change event for the update is received and printed. The output includes the Changed Fields section, which contains the fields that were expanded from thechangedFields
bitmap field. It lists the two fields that were changed: theType
field that you changed, and theLastModifiedDate
field that the system changed. For example:
The ProcessChangeEventHeader
class is implemented in ProcessChangeEventHeader.java. The ProcessChangeEventHeader
class uses the Subscribe
RPC method, which is implemented in Subscribe.java.
See Subscribe RPC Method.
See Also
- Change Data Capture Developer Guide: ChangeEventHeader Fields
- Event Deserialization Considerations