I am publishing a platform event which is having one long text area field. The field will have record ids in comma separated way ('id1, id2,id3...'). After publishing the event from apex class getting error INVALID_FIELD_FOR_INSERT_UPDATE - The event can't be published because it contains an ID value. my code:

 List<id> Recid= new list<id>();
 //recid id can contain 50 ids 
 String Str=String.join(Recid,',');
            system.debug('last batch ids>>'+Str);
            newsEventList.add(new PlatformEvent__e(H_Ids__c=Str)); 
            List<Database.SaveResult> results = EventBus.publish(newsEventList);
          // Inspect publishing result for each event
             for (Database.SaveResult sr : results) {
                if (sr.isSuccess()) {
                    System.debug('Successfully published event.');
                    for(Database.Error err : sr.getErrors()) {
                        System.debug('Error returned: ' +
                                    err.getStatusCode() +
                                    ' - ' +

can anyone please let me know why getting error?


1 Answer 1


Issue was occurring due because I was not clearing the event list each time after the event was triggered. The below code resolve the issue:

if(!newaccountChangeEvent.isEmpty()) { List<Database.SaveResult> results = EventBus.publish(newEventsList); newEventsList.clear(); ... }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .