Skip to main content

Hi,

I am trying to create a platform event when the parent object field X changes, subscribe to the event in the apex batch job or queueable job, and update the child object record Y field with the parent object record field X.

 Can anyone answer me with an example?

 

I know I can create the platform event as following

 

public class ParentObjectHandler {

    public static void handleParentObject(List<parentObject> parentObjectList) {

        List<parentobject__e> platformEvents = new List<parentobject__e__e>();

       

        for (parentobject  pob : parentObjectList) {

            if (pob.X != null) {

                parentobject__e platformEvent = new parentobject__e();

               

                platformEvent.X = pob.X;

                platformEvents.add(platformEvent);

            }

        }

       

        if (!platformEvents.isEmpty()) {

            EventBus.publish(platformEvents);

        }

    }

}

How to subscribe and update child object records?

2 answers
0/9000