0

I am publishing the platform event in one salesforce org to another org though HTTP callout. The target org is listening to the event for the first record. i.e. If the source org publish 5 records, the target org is listening the first record.

Here is my logic:

/*Scheduler */ public class SchedulerClass{ //Get all the records from staging table and initiate queueable ID jobID = System.enqueueJob(new QueuableClass(stagingList)); } /*Queueable Class */ public class QueuableClass{ public QueuableClass(stagingList){ this.stagingList = stagingList; } public void execute(QueueableContext context){ Stage_Object stageRec = stagingList.remove(0); doCallout(stageRec); if(stagingList!= null && stagingList.size() >0){ ID jobID = System.enqueueJob(new QueuableClass(stagingList)); } } private void doCallout(stageRec){ HttpRequest request= new HttpRequest(); request.setMethod('POST'); request.setEndpoint('callout:targeOrg/services/data/v58.0/sobjects/eventUpdate__e'); request.setHeader('Content-Type','application/json;charset=UTF-8'); request.setBody(); Http http = new Http(); HTTPResponse response = http.send(request); } } 

The debug log in the source org is showing that the PE is fired successfully for all the records in the list but the in target org, the debug log for 'Automated User' is showing the first record.

5
  • we need more details to troubleshoot it. What is a response of http.send(request); ? what trigger/flow are you using for handling published events? Commented Dec 30, 2024 at 19:09
  • the response from the callout is success. i.e Returning status code 201. The idea is to check the callout response and update the staging table within the same queueable class. Commented Dec 30, 2024 at 19:12
  • Welcome to SFSE! Please take a moment to read How to Ask and take the tour. Including a Minimal, Complete and Reproducible example would be helpful. Your example is somewhat Minimal, not Complete and therefore not Reproducible. Commented Dec 30, 2024 at 20:26
  • Assuming the target org didn't disable the subscription after the first record; are you sure the debug in the target org is not showing record[0] when in fact the subscriber trigger is likely processing a batch of n (n=5 in your example) records ? Commented Dec 31, 2024 at 1:12
  • I am sure that the target org is not disabling the subscription after the first. The publishing & subscribing is really behaving different. i.e if I publish 3 records from source the automated user in the target org is subscribing 2 records(added system debug in the subscription trigger to see the event details). If I publish 2 records, receiving only 1 record in the target. Another observation is, I moved the callout logic from queueable to batch apex and set the batch size to 1, now the all the subscription is working for all the records. Commented Dec 31, 2024 at 21:51

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.