Update Field Names for Salesforce Production#756
Conversation
Test coverage90.16% line coverage reported by SimpleCov. |
There was a problem hiding this comment.
Pull request overview
Updates the Rails-to-Salesforce sync to align with production Salesforce field naming and to support setting a “New” status when a School is first created.
Changes:
- Split School Salesforce sync callbacks to distinguish create vs update and pass
is_createintoSalesforce::SchoolSyncJob. - Update Salesforce school/contact/role field mappings to new production field names.
- Add logic to set Salesforce School
status__cto"New"on create.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| app/models/school.rb | Splits after_commit sync callbacks and passes is_create into the School sync job. |
| app/jobs/salesforce/school_sync_job.rb | Adds editortype__c mapping and sets status__c on create. |
| app/jobs/salesforce/role_sync_job.rb | Sets editor_type__c on the Salesforce affiliation record based on the school’s user_origin. |
| app/jobs/salesforce/contact_sync_job.rb | Renames the Salesforce Contact field written for UX contact consent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| after_create :generate_code! | ||
|
|
||
| after_commit :do_salesforce_sync, on: %i[create update], if: -> { FeatureFlags.salesforce_sync? } | ||
| after_commit -> { do_salesforce_sync(is_create: true) }, on: :create, if: -> { FeatureFlags.salesforce_sync? } | ||
| after_commit -> { do_salesforce_sync(is_create: false) }, on: :update, if: -> { FeatureFlags.salesforce_sync? } |
There was a problem hiding this comment.
after_create :generate_code! performs an update!, so creating a School will include both :create and :update actions in the same transaction. With separate after_commit callbacks for on: :create and on: :update, this can enqueue Salesforce sync jobs twice on initial creation (once with is_create: true and again with is_create: false). Consider consolidating to a single callback that computes is_create (or adding a guard so the update callback doesn’t run for the initial code-generation update).
There was a problem hiding this comment.
I don't believe this is correct. I have a passing test in school_spec.rb named "enqueues Salesforce::SchoolSyncJob exactly once on create, with is_create: true'.
5e5fbfc to
b7f9eed
Compare
This commit changes a number of field names to match those requested by the Salesforce team. Also, we now pass a flag into School#do_salesforce_sync to indicate whether this is a new school (create) or an existing school (update). This allows us to set the `status__c` field of the school to "New" if it's a new school, otherwise leave it alone.
b7f9eed to
698ef6e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This commit changes a number of field names to match those requested by the Salesforce team.
Status
Points for consideration:
What's changed?
status__cfield of the school to "New" if it's a new school, otherwise leave it alone.Steps to perform after deploying to production
After deploying and testing in Staging, we will apply https://github.com/RaspberryPiFoundation/terraform/pull/1306 to enable this feature in production.