I have a rest API endpoint in Salesforce which accepts a payload from my application. On reception of the first request with a given email, it creates a lead. On subsequent requests, it finds the lead and updates the lead with extra information in the payload. My problem is that if a user quickly moves through the process (like have most of the fields filled and they just click the next button, it is a wizard-like interface), I have to call the API in quick succession. While the first call is creating the lead, the second call searches for a lead with a given email (which is not created yet) and starts the call to create a new lead. In the meantime, the first call has finished creating the lead as well. Now I have 2 leads instead of one :(
Is there a way on the Salesforce side I can handle this? Can't change the way requests land, sorry.