-
Notifications
You must be signed in to change notification settings - Fork 5
Salesforce integration #577
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements Salesforce integration to synchronize newly-verified School records into Salesforce as Account records, supporting the ExperienceCS customer success team.
- Adds
SalesforceSyncJobto create Salesforce Account records when schools are verified - Integrates the
restforcegem for Salesforce API communication - Configures Salesforce credentials via environment variables
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| app/models/school.rb | Enqueues SalesforceSyncJob when a school is verified |
| app/jobs/salesforce_sync_job.rb | New job that creates Salesforce Account records with school data |
| spec/models/school_spec.rb | Adds test verifying job enqueue on school verification |
| spec/jobs/salesforce_sync_job_spec.rb | Comprehensive tests for Salesforce sync job behavior |
| Gemfile | Adds restforce gem dependency |
| .env.example | Documents required Salesforce environment variables |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def client | ||
| Restforce.new( | ||
| username: ENV.fetch('SALESFORCE_USERNAME'), | ||
| password: ENV.fetch('SALESFORCE_PASSWORD'), | ||
| client_id: ENV.fetch('SALESFORCE_CLIENT_ID'), | ||
| client_secret: ENV.fetch('SALESFORCE_CLIENT_SECRET'), | ||
| host: ENV.fetch('SALESFORCE_HOST'), | ||
| api_version: '57.0' | ||
| ) | ||
| end |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Restforce client is being instantiated on every job execution. Consider memoizing the client with @client ||= to avoid recreating the connection for potential retry scenarios.
| client.create('Account', account_data) | ||
| end |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Salesforce API call has no error handling. If the API call fails, the job will raise an exception with no context about which school failed to sync. Consider wrapping this in a rescue block that logs the school_id and re-raises, or let the job framework handle retries with better error context.
| client.create('Account', account_data) | |
| end | |
| begin | |
| client.create('Account', account_data) | |
| rescue => e | |
| Rails.logger.error("SalesforceSyncJob failed for school_id=#{school_id}: #{e.class} - #{e.message}") | |
| raise | |
| end |
|
|
||
| true |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The explicit true return value is unnecessary since perform_later already returns a truthy value. If an explicit boolean return is required for the method contract, consider documenting why this is needed.
| true |
In order to support the ExperienceCS customer success team, this PR ensures that newly-verified School records are synchronised into Salesforce as
Accountrecords.Setting up a Salesforce account and application in the Sandbox
The RPF sandbox salesforce environment is here: https://raspberrypi--digital.sandbox.lightning.force.com
Step 1
Liesl Quinn created me an account using my
[email protected]email address. She sent me a password reset email to allow me to set a new password, and changed my profile to allow API access.Step 2
Once in salesforce I needed to
View profile > My personal information > Reset my security tokento generate a new security token.Step 3
I then visited
Setup > Setup for current app > platform tools > Apps > External Client Apps > Settingsand enabled "Allow creation of connected apps".I clicked "New Connected App"
I created an
editorapiapp with OAuth settings:I copied the Consumer key and secret from "Manage consumer details".
Connecting to salesforce using
restforceWith the above in place I was able to use
restforceto connect to salesforce:Where
usernameandpasswordare from step 1,security_tokenfrom step 2 andclient_id/client_secretfrom step 3 above. Note that thehostis not the same as the URL you use to login to salesforce,lightning.force.comis replaced withmy.salesforce.com.I could then create an
Accountin Salesforce withTODO
editorapiapplication with correct usereditorapito the minimum required (currently "Full access" in the salesforce sandbox)Clientrecords in Salesforce or if these are already created as part of another sync.Applicationrecord in Salesforce. This is suggested in the google sheet Jason and Emma put together, but I can't see it defined in the sandbox environment