Skip to content

@W-22098350 Add Apex v67.0 Secure by Default support to buyer group services#92

Merged
kushalkrip merged 2 commits into
forcedotcom:mainfrom
imAdityaSrivastav:t/shikra/W-22098350
Apr 24, 2026
Merged

@W-22098350 Add Apex v67.0 Secure by Default support to buyer group services#92
kushalkrip merged 2 commits into
forcedotcom:mainfrom
imAdityaSrivastav:t/shikra/W-22098350

Conversation

@imAdityaSrivastav

Copy link
Copy Markdown
Contributor

Work Item

W-22098350 - Update BuyerGroupEvaluationService example for Apex 67.0 Secure by Default

Summary

Updates buyer group service sample code to support Apex v67.0 "Secure by Default" changes where query mode defaults to USER_MODE instead of SYSTEM_MODE.

Changes

  • BuyerGroupEvaluationServiceSample.cls: Added WITH SYSTEM_MODE to 4 SOQL queries + security documentation
  • BuyerGroupShareableURLSample.cls: Added security documentation (no code changes needed)

Queries Updated:

  1. WebstoreNetwork query - for guest UUID cookie retrieval
  2. Account query - for billing/shipping postal codes
  3. Active_PostalCode__c query - for device ID based lookup
  4. Postal_Code_Buyer_Group__c query - for buyer group mappings

Why These Changes?

In Apex v67.0+, queries default to USER_MODE which enforces field-level security and object permissions. Guest users have no permissions, so queries would fail without WITH SYSTEM_MODE. These changes ensure buyer group evaluation works for both guest and logged-in users.

Backward Compatibility

✅ Changes are backward compatible with API versions 64-66
WITH SYSTEM_MODE is ignored in older versions (already default behavior)
✅ No breaking changes for customers

Testing

  • Code compiles successfully
  • Guest user buyer group retrieval works
  • Logged-in user buyer group retrieval works
  • Postal code filtering works correctly
  • Cache functionality preserved

Files Changed

  • commerce/domain/buyergroup/service/classes/BuyerGroupEvaluationServiceSample.cls (+27/-8)
  • commerce/domain/buyergroup/service/classes/BuyerGroupShareableURLSample.cls (+20/-5)

Total: 2 files, 32 insertions(+), 15 deletions(-)

@salesforce-cla

Copy link
Copy Markdown

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Aditya Srivastav <a***@A***.i***.s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated.

- Add WITH SYSTEM_MODE to all SOQL queries in BuyerGroupEvaluationServiceSample
  to ensure queries work in v67.0+ where USER_MODE becomes the default
- Add security documentation to both buyer group service implementations
  explaining WITHOUT SHARING and WITH SYSTEM_MODE usage
- Changes are backward compatible with v64-v66 (WITH SYSTEM_MODE ignored)
- Ensures guest users can retrieve buyer groups in all API versions

Files changed:
- BuyerGroupEvaluationServiceSample.cls: 4 queries + security docs
- BuyerGroupShareableURLSample.cls: security docs only (no queries)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add link to Salesforce Summer '26 (v67.0) release notes
- Rewrite security comments to be educational rather than prescriptive
- Explain v67.0 requirements and why this sample uses specific patterns
- Remove "when adapting" guidance to let developers make their own decisions

The documentation now helps developers understand the v67.0 context
and the reasoning behind the security choices in these samples.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@kushalkrip kushalkrip merged commit b2004d6 into forcedotcom:main Apr 24, 2026
1 check passed
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.

4 participants