We are using Salesforce with our Drupal site for Registrations and Orders. When someone submits their registrations, we us a SOQL query to lookup Contacts with matching First Name, Last Name, and Email. If we find one we update fields if needed and save the returned ID and if we didn't we create a new one and store the new ID.
This works excellent 98% of the time but we are noticing some duplicate Contacts being created at the same time. A duplicate is only created if they were brand new records. What we think is happening is people can register for more than one event at a time and are presented with multiple registration forms for each event. The query runs for the first one and creates/updates and then runs again for the next one and so on.
Doing some research it seems that newly created records are not always immediately available to be queried again because it needs to be indexed. So after the first Contact is created, the next time we query First Name, Last Name, and Email we return no results if the other record hasn't been indexed yet.
One thought to perhaps remedy this is to store the newly created Contact into a db table with its ID, First Name, Last Name, and Email and before we run our normal query against Salesforce, we query our db table to see if it exists and grab the ID and only use the ID in the SOQL query to find a match.
But this will only solve the problem if the Salesforce ID is immediately and always available for SOQL queries and isn't subject to indexing and just the more detailed record information like names and emails are.
Does anyone know if this is true? Can you immediately query IDs in Salesforce without worrying about indexing issues? This is difficult to test at the moment since it's so sporadic.