Step 5: Subscribe to Change Events
Subscribe to change events and perform bitmap field expansion. By setting a flag in arguments.yaml, the Subscribe example expands the changedFields bitmap fields in change events into its component fields.
Change event headers are described in ChangeEventHeader Fields in the Change Data Capture Developer Guide. To learn more about bitmap field expansion, see Event Deserialization Considerations.
Prerequisites
- Because this 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-apifolder, go tojava/src/main/resourcesand open thearguments.yamlfile.- Provide the change event channel:
TOPIC: /data/OpportunityChangeEvent - Enable bitmap field expansion for ChangeEventHeader:
PROCESS_CHANGE_EVENT_HEADER_FIELDS: true.
- Provide the change event channel:
-
In a Terminal window, navigate to the
javafolder. -
To run the example, from the top-level
javafolder, enter:./run.sh genericpubsub.SubscribeThe example subscribes to the
/data/OpportunityChangeEventchannel and captures any new or changed Opportunity records. -
In Salesforce, create an opportunity record. The change event is received and printed. For example:
-
Update the opportunity record. For example, select a
TypeofNew 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
changedFieldsbitmap field. It lists the two fields that were changed: theTypefield that you changed, and theLastModifiedDatefield that the system changed. For example:
The client code for the Pub/Sub API RPC methods is in the genericpubsub folder. To check out the implementation for each RPC method, open the corresponding Java file in the genericpubsub folder. For the Subscribe example, open Subscribe.java.
See Subscribe RPC Method.
See Also
- Change Data Capture Developer Guide: ChangeEventHeader Fields
- Event Deserialization Considerations