0

Whenever an update happens in Salesforce from a third party system, we have to make sure that we don't fire the platform events and to ensure that we have a checkbox in place which is set to true by the third-party system. So, once the checkbox is true, we can prevent the platform events from firing in after trigger, but to make sure that the platform events fire for any other next transaction we'll have to uncheck the checkbox as well. I am just confused if it's possible to set the checkbox in the same transaction which was triggered by the third party system and that too in after trigger.

I was thinking of a future method, but then again there are chances that I might miss some updates on that particular record till the time future is fired to disable the checkbox. Am I missing something?

Any help is appreciated!

1
  • 1
    Why can't you use a before update trigger? Sorry if I missed something. – Girbot Dec 17 '20 at 15:25
1

The trick is to not send to update the very same record, that went into a trigger.

One way to do this is to generate a new record with the same ID and the correct field value. E.g.:

new Account(Id = existingRecord.Id, SkipEvent__c = false);

But I would consider options without update in the After. For example update a separate field UpdateSource based on the checkbox. If checkbox is true - set it to external system. Else set to Salesforce. Set checkbox to false after that in the Before trigger. And send event based on UpdateSource: if source is external system - do not send the event.

Another thing to consider is to always send event, and handle update/not-update on the consumer side. That will allow to scale easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.