I am trying to create a Salesforce object in my Rails app. When I do so, the object is created on the Salesforce end and it might take a few seconds for the object to be populated with the SFID before it's available in my Rails app.
The issue is, I need this SFID in order to create subsequent models (for example, I create an Order but I need the Order SFID to create the OrderItem or Shipment) in order to proceed.
For whatever reason, I can't create a timeout loop until the SFID is available because it doesn't seem to have access to the Heroku Connect sync inside said loop (I have tried clearing the cache inside the loop), so I am currently using the below sleep method which I am sure is not the best way of doing so. Is there a more efficient way?
clientsiteid__c = @order.clientsiteid__c
@order = Order.find_by(clientsiteid__c: clientsiteid__c)
# adding second retry in case the order id was not found
if !@order.id
sleep 10
@order = Order.find_by(clientsiteid__c: clientsiteid__c)
end
# adding third retry in case the order id was not found
if !@order.id
sleep 45
@order = Order.find_by(clientsiteid__c: clientsiteid__c)
end
# adding fourth retry in case the order id was not found
if !@order.id
sleep 120
@order = Order.find_by(clientsiteid__c: clientsiteid__c)
end