Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create or update a lead instead of trying to time creation #1211

Merged
merged 18 commits into from
Nov 28, 2023

Conversation

mwvolo
Copy link
Member

@mwvolo mwvolo commented Nov 14, 2023

We are noticing not all leads are making it into Salesforce and thinking they are getting caught up in a timing issue between the SheerID webhook response and them filling out their profile.
This will allow us to create and update the lead if necessary (upon hearing back from SheerID).

This also creates a lead for folks that did the verification step but still need to complete their profile, setting the lead FV status to 'Incomplete Signup', allowing us to market to them and try to get them back to fill out their profile.

@mwvolo mwvolo requested a review from Dantemss November 14, 2023 21:30
Copy link
Member

@Dantemss Dantemss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a race condition regardless of you doing the suggestion below or not, as the record can change in between the find and the save. Ideally we'd use an upsert API from Salesforce, if possible. But if it doesn't exist then this should be mostly fine... or at least better than what is there now.

)
user.faculty_status = User::INCOMPLETE_SIGNUP unless user.is_profile_complete?

lead = OpenStax::Salesforce::Remote::Lead.find_by(email: user.best_email_address_for_salesforce)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably do

lead = OpenStax::Salesforce::Remote::Lead.find_by(email: user.best_email_address_for_salesforce) || OpenStax::Salesforce::Remote::Lead.new(email: user.best_email_address_for_salesforce)

and then you don't need the if as the logic is the same after that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this, but unfortunately, it needs the school to create a new one, so it doesn't work with the ||.
Maybe I can add the school into that call... but let me think about the implications of that (like if the school gets updated).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dantemss I think it's best (not a fan of the duplication) to keep the if statement. I changed it slightly to check if the user has a salesforce_lead_id if so, search for them by email, which I think will cover some of the lead merging that could happen on the salesforce side.
Let me know if you think otherwise -- ready for another look when you have a chance.

@mwvolo
Copy link
Member Author

mwvolo commented Nov 15, 2023

Will need to merge/release openstax/openstax_salesforce#74 before tests will pass

@mwvolo
Copy link
Member Author

mwvolo commented Nov 15, 2023

Also of note: I removed the lead creation for students wanting the newsletter. This was failing because a lead needs a school, which we do not collect from students.
We can revisit this in the future (since it wasn't working anyway) and use a manual process with Blazer to update those wishing to receive the newsletter in the meantime.

@mwvolo
Copy link
Member Author

mwvolo commented Nov 17, 2023

Will rerecord cassettes for SF after we merge this: openstax/openstax_salesforce#75

@mwvolo mwvolo requested a review from Dantemss November 27, 2023 19:46


if user.salesforce_lead_id
lead = OpenStax::Salesforce::Remote::Lead.find_by(email: user.best_email_address_for_salesforce)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK finding by email here because I remember you writing something about the lead IDs changing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, exactly - they could merge on the Salesforce side if they already have a lead and it'll change the id (then it updates it on the user later down the script)

@mwvolo mwvolo merged commit fd86ffd into main Nov 28, 2023
7 checks passed
@mwvolo mwvolo deleted the create-lead-for-incomplete-signup branch November 28, 2023 21:19
@mwvolo mwvolo linked an issue Dec 4, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create/update a lead after SheerID callback and when profile is complete
2 participants