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

Resubmit Apex Callout from Queueable

I am working on an assignment where I need to process some subscribed events in Salesforce when a third party system publishes an event. The third party system publishes an event when there is a change in a database record. We have a middleware application that reads the messages from the third party's event bus and makes a rest API callout to insert a record into a platform event object with the event/database record details.

In Salesforce, I have developed an apex trigger on the Platform event object that executes a service class that is implementing Queueable. The queueable class reads the event details and makes a callout to the third party API to get further details about the record that was changed and performs an upsert into the Asset object in Salesforce. So far, it is going good. However, while testing, I found certain scenarios that need to be addressed and I am not sure of an efficient way of doing those. Below are the scenarios that need to be addressed.

1) I see that the third party API is returning a 204 - No Content at times. In that case, I need to queue that event again so that it needs to be re-processed. How do I do this?
Bu2) siness wants me to perform an upsert only there are real data changes on the Asset object. The third party system is pushing several dummy updates and I want to ignore them. My idea is to create an AssetTemplate class and build two maps of definition Map<externalId, AssetTemplate> where one map will be populated from the response of third party API and the second map will be populated from the Asset object. Then I will loop through the APIResponseMap, find the corresponding map element from the AssetMap, compare the AssetTemplate objects in them and if they are different, then build a new Map with the externalId as Key and AssetTemplate as the value. Finally, I will loop through the final map and perform an upsert on the Asset object in Salesforce. Is there a better way of doing this?

Can someone help?