b2c-controllers_skill

This skill guides you in creating storefront controllers for SFRA or classic B2C patterns to handle requests, render responses, and generate URLs.
  • TypeScript

20

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill salesforcecommercecloud/b2c-developer-tooling --skill b2c-controllers

  • SKILL.md8.4 KB

Overview

This skill creates storefront controllers for Salesforce B2C Commerce using SFRA or classic patterns. It helps you build page handlers, form endpoints, AJAX responses, and middleware-enabled routes while supporting URL generation with URLUtils. The skill focuses on practical controller structure, request/response handling, and safe error and middleware patterns.

How this skill works

It inspects controller conventions and generates modules under a cartridge's controllers directory. For SFRA it scaffolds server.get/server.post routes with middleware chains, view data handling, res.render/res.json usage, and server.exports. For classic sites it produces direct exports with .public = true and ISML rendering. It also wires common imports like ProductMgr, Transaction, Logger, and URLUtils and recommends where to place business logic in helper scripts.

When to use it

  • Building storefront pages that render ISML templates or view models
  • Handling form submissions, AJAX calls, or JSON endpoints
  • Applying middleware like HTTPS enforcement, CSRF checks, or caching
  • Extending or overriding existing controller routes in SFRA
  • Generating locale-aware URLs or static resource links with URLUtils

Best practices

  • Prefer SFRA server module for most storefront controllers; use classic only for simple non-SFRA endpoints
  • Keep controllers thin: move business logic into helper scripts or services
  • Always call next() in SFRA middleware handlers to continue the chain
  • Validate input, wrap risky operations in try/catch, and avoid exposing stack traces
  • Use */cartridge/ paths for portable imports and require modules only when needed

Example use cases

  • Create a Home-Show route that renders the homepage with a prepared view model
  • Add a POST Subscribe endpoint that accepts form.email and returns res.json success
  • Apply cache and consent middleware to a product listing page for optimized delivery
  • Extend an existing Cart-Show route to append custom view data before render
  • Build a JSON API endpoint in a classic controller and mark it public for AJAX clients

FAQ

Use server.middleware.https on routes that handle sensitive data or logins to force HTTPS before the handler executes.

How do I generate a locale-aware controller URL?

Use URLUtils.url('Controller-Action', 'param', value) for standard URLs or URLUtils.https/url/staticURL for HTTPS and static resources.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
b2c-controllers skill by salesforcecommercecloud/b2c-developer-tooling | VeilStrat