Posts

Showing posts from April, 2020

CDC - How to Reconstruct a Field from Its Diff Value

CDC-  Reconstruct a Field from Its Diff Value in Apex The following code sample can be used to reconstruct a long textarea field from its Diff value in a CDC packet. I have written it as a utility method which would need you to parse the CDC JSON packet and query the current value of the field from your DB. This is going to be useful when you are using CDC to keep 2 salesforce orgs in sync. On the listener side you need to implement this as part of CDC packet consumption. The first parameter (oldText) is the current value in the database before applying the CDC packet. The diff string is the parsed value from the CDC packet. For a JSON Node like " Description":{ "diff":"--- \n+++ 682b8747ccdb93b546e7bbe479b27d26ec7c38ccabb76cdd8308c6595492bffc\n@@ -2,1 +2,1 @@\n-Business applications are moving to the cloud. It’s not just a fad—the shift from traditional software models to the Internet has steadily gained momentum over the last 10 years.\n+Bus...