Skip to content

Update Field Names for Salesforce Production#756

Merged
fspeirs merged 1 commit intomainfrom
fs-update-salesforce-for-final-production
Mar 30, 2026
Merged

Update Field Names for Salesforce Production#756
fspeirs merged 1 commit intomainfrom
fs-update-salesforce-for-final-production

Conversation

@fspeirs
Copy link
Copy Markdown
Contributor

@fspeirs fspeirs commented Mar 30, 2026

This commit changes a number of field names to match those requested by the Salesforce team.

Status

Points for consideration:

  • Security
  • Performance

What's changed?

  • A number of fields have been renamed.
  • 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.

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.

Copilot AI review requested due to automatic review settings March 30, 2026 10:19
@cla-bot cla-bot bot added the cla-signed label Mar 30, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 30, 2026

Test coverage

90.16% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/23741247161

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_create into Salesforce::SchoolSyncJob.
  • Update Salesforce school/contact/role field mappings to new production field names.
  • Add logic to set Salesforce School status__c to "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.

Comment on lines 56 to +59
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? }
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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'.

@fspeirs fspeirs force-pushed the fs-update-salesforce-for-final-production branch 2 times, most recently from 5e5fbfc to b7f9eed Compare March 30, 2026 10:48
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.
@fspeirs fspeirs force-pushed the fs-update-salesforce-for-final-production branch from b7f9eed to 698ef6e Compare March 30, 2026 10:57
@fspeirs fspeirs requested a review from Copilot March 30, 2026 10:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@fspeirs fspeirs merged commit 2916616 into main Mar 30, 2026
9 checks passed
@fspeirs fspeirs deleted the fs-update-salesforce-for-final-production branch March 30, 2026 15:36
@fspeirs fspeirs self-assigned this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants