function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pugalagiri JPugalagiri J 

TriggerFactory for Change Data Capture Trigger

I am working on framework (triggerFactory) for change data capture (subscriped via trigger),
This framework will be generic framework and should be used by all objects when enabled for change data capture. Inorder to make it generic we are planning to create a wrapper class and include all fields of trigger.new in wrapper class.

1, In case of UPDATE, we have change fields and passing only the changed fields to wrapper class as sObject
2, In case of INSERT, we dont have a parameter to identify what all fields are inserted. Either need to wrap all fields or only wrap only inserted fields.

Is there anyway to fetch all fields in change event(trigger.new) and pass to wrapper class as sobject ?

example: (new Account created)
Event will be as below (trigger.new):

AccountchangeEvent
{
Id=000GFHuy76,
ReplayId=000AQMhhg67,
ChangeEentHeader=eventbus.ChaneEventHeader [getchangeFields=(), getCommitNum=43,.....],
Division=null,
FirstName=null,
LastName=null,
Name='TestAccount',
BillingCity=null
}

In Need to create sobject in wrapper class as below
Account:{Division=null,
FirstName=null,
LastName=null,
Name='TestAccount',
BillingCity=null}

Manually fething field one by one and passing to wrapper class is not a good solution. Is there any way all fields in event can be read and passed to wrapper ?
ShivankurShivankur (Salesforce Developers) 
Hi Pugalagiri,

I see similar discussion thread and some useful code is been shared on below link:
https://developer.salesforce.com/forums/?id=906F00000008xFXIAY

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
Pugalagiri JPugalagiri J
Thanks for the inputs
I have achieved it using getPopulatedFieldsAsMap() and then created sObject with needed fields