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
Kritika RajKritika Raj 

Platform Events - The Replay Id of child event is less than the parent event

I am publishing the events in such a way that first the controller executes the publish method for Parent and then the child . In System.debug , the statements are printed accordingly such as 
- Successfully Published Parent Event
- Successfully Published Child Event

But the Child replayId is less and Parent is greater indicating that child event was published first . Please , can someone explain the reason why this might happen?
vijaya kumar 29vijaya kumar 29
Hi raj,

Replay ID values are not guaranteed to be contiguous for consecutive events. For example, the event following the event with ID 999 can have an ID of 1,025.

Get more details about replay ID and platform event. 

https://trailhead.salesforce.com/en/content/learn/modules/platform_events_basics/platform_events_define_publish
 
AnudeepAnudeep (Salesforce Developers) 
This is working as documented. As long as the events are consecutive, the replayIds will increase (ReplayIDs for consecutive events in the bus may not be contiguous but should always increase (never decrease))

Coming to order of events. Events are added in chronological order with replay IDs

 
Kritika RajKritika Raj
The issue I am facing is that I am calling the publishmethod for Parent Event first and then for the Child event . I understand that it is not necessary that the Replay Id will be continuous but it should be in increasing order. Still I can see that the ReplayId of child is less than its parent .
Kritika RajKritika Raj
Platform Evnet for Parent is created first but the Replay Id is more . As you can see in the Screenshot below , the Parent Created Date is - 
2020-08-06 06:17:20 but Replay Id is - 4909User-added image
AnudeepAnudeep (Salesforce Developers) 
Please raise a support case and provide these example timestamps.
Support can review server logs and provide the cause of this behavior or confirm whether or not this is working as designed. Thanks