0

I have made the integration process between salesforce and our external system. the idea is that all Lead Status Changes in Salesforce must be recorded in our External system. For sending data when the lead status changes, it has been implemented successfully, but I have problems if sending data via REST API fails, the Lead status in Salesforce must be returned to its previous value (Rollback). Currently, when sending data via REST API fails, the Lead Status in Salesforce is still changing and this raises the issue of data integration between Salesforce and our external systems.

the following is additional information that may help you understand my problem:

  1. I use the Future Method for sending data
  2. Future methods are called through the process builder to trigger the process. The criteria are simple, if the lead status changes is true, run the apex class for sending lead status to our external system

I have tried several ways, such as trying to update them through the process builder and creating triggers, but due to my lack of knowledge and experience, it hasn't worked.

Please help if anyone knows the best way and how to solve this problem.

This is my first experience doing a system integration with Salesforce, I really appreciate all your help.

Thank you

1 Answer 1

0

I can see a couple of options

Option 1 - Pass to the future method the prior value of Lead Status

When the callout fails, the future method can do DML on the original Lead and reset its Lead Status (you'll need to prevent recursion so this DML update doesn't call the future again!)

Option 2 - Rely on field history

When the callout fails, the future method can query the lead's LeadHistory object and find the prior value of Lead.Status, then use DML to reset its Lead Status (you'll need to prevent recursion so this DML update doesn't call the future again!)

Preventing recursion can be done with a static map of LeadIds.

All that said, a far better design would be to not revert the SFDC Lead.Status but instead log the callout error somewhere and have a retry process. There are various patterns out there to do this (I use the Appleman Advanced Apex 4th edition Going Async pattern)

1
  • Thankyou for your help
    – Putra
    Mar 10, 2021 at 18:10

You must log in to answer this question.

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