Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nfriend21/c17c758fa62901ddc8963edb681e81d3 to your computer and use it in GitHub Desktop.
Save nfriend21/c17c758fa62901ddc8963edb681e81d3 to your computer and use it in GitHub Desktop.
# The actual string of the start date and end date in the two lines below need to be adjusted to reflect the date range of the inquiries you want to update.
# This script is safe to run even on inquiries that successfully sync'd to Salesforce. Therefore, you dont need to find the exact Inquiries that didnt sync,
# you can just run this for the entire day where the problem occured.
start_date = Time.strptime('05-11-2021', '%m-%d-%Y').beginning_of_day.in_time_zone
end_date = Time.strptime('05-12-2021', '%m-%d-%Y').end_of_day.in_time_zone
errors = []
Inquiry.where('created_at >= ? AND created_at < ?', start_date, end_date).each do |i|
client = SalesforceConnector.client
lead_id = client.query("select Id, Email from Lead where Email = '#{i.email.delete(' ')}'").first.try(:Id) || 'x'
begin
sf_lead = client.find('Lead', lead_id)
rescue Faraday::Error::ResourceNotFound
begin
SalesforceLeadUpdater.create_lead(i.lead, i, nil, nil)
i.update_attributes(reconciled_in_salesforce: true)
rescue => e
errors << [i.id, "ERROR 2======#{e}"]
end
rescue => e
errors << [i.id, "ERROR 3======#{e}"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment