I wanted to split a map value which has a size of 2000 into small lists of max size 600 each and publish this smaller lists using platform events. I'm performing an update using platform event triggers. What's the best way of doing it ? Below is my code
if(WrapObjMap.keyset().size() > maxSizePerReq) {
system.debug('Inside If');
for(Integer i = 0 ; i < (WrapObjMap.keyset().size() / 600)+1 ; i++){
SplitList = new List<platform_Event__e>();
SplitFinalList = new List<platform_Event__e>();
for(Integer j=(i*600); (j<(i*600)+600) && j<WrapObjMap.keyset().size() ; j++){
SplitList.add(new platform_Event__e(long_text_area_field__c = JSON.serialize(WrapObjMap.values().get(j))));
}
List<Database.SaveResult> results = EventBus.publish(SplitList);
}
}