Created
October 15, 2021 12:54
-
-
Save nfriend21/9fc538b8687f709deb3a37e63e8893db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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('10-15-2021', '%m-%d-%Y').beginning_of_day.in_time_zone | |
end_date = Time.strptime('10-15-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) | |
if sf_lead["ConvertedOpportunityId"].present? | |
i.update_attributes(reconciled_in_salesforce: true) | |
else | |
begin | |
SalesforceLeadUpdater.fix_update_lead_from_inquiry(i) | |
i.update_attributes(reconciled_in_salesforce: true) | |
rescue => e | |
errors << [i.id, "ERROR 1======#{e}"] | |
end | |
end | |
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