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

  1. In your pub-sub-api folder, navigate to java/src/main/resources and open thearguments.yaml file. Provide the change event channel as the TOPIC argument.

    1. TOPIC: /data/OpportunityChangeEvent
  2. In a Terminal window, navigate to the java folder.

  3. To run the example, from the top-level java folder, enter: ./run.sh processchangeeventheader.ProcessChangeEventHeader

    1. The example subscribes to the /data/OpportunityChangeEvent channel and captures any new or changed Opportunity records.
  4. The example prints out logging information similar to:

  5. In Salesforce, create an opportunity record. The change event is received and printed. For example:

  6. Update the opportunity record. For example, select a Type of New 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 the changedFields bitmap field. It lists the two fields that were changed: the Type field that you changed, and the LastModifiedDate 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