Skip to content

trailheadapps/multiframework-recipes

Multiframework Recipes

CI codecov

React Recipes

A collection of easy-to-digest code examples for building apps on the Salesforce platform using modern frontend frameworks. Each recipe demonstrates how to accomplish a specific task — from querying data with GraphQL to handling errors and navigating between views — in the fewest lines of code possible while following best practices. Each recipe includes an inline source code viewer so you can see exactly how it works.

This sample application is designed to run on the Salesforce Platform. It covers what a frontend developer needs to know about Salesforce, and what a Salesforce developer needs to know about modern frameworks — taught at the intersection.

Multi-Framework currently supports React, with additional frameworks coming over time.

Learn more: Read the Salesforce Multi-Framework developer guide for a comprehensive overview.

Architecture

graph LR
    A[React App<br/>Vite + TypeScript] -->|Build| B[UI Bundle]
    B -->|Deploy| C[Salesforce Org]
    C -->|Query| D[GraphQL UIAPI]
    C -->|Fetch| E[REST APIs]
Loading

Table of Contents

Setting up a Scratch Org

  1. Set up your environment. Follow the steps in the Quick Start: Lightning Web Components Trailhead project. The steps include:

    • Enable Dev Hub in your Trailhead Playground
    • Install Salesforce CLI
    • Install Visual Studio Code
    • Install the Visual Studio Code Salesforce extensions
  2. Make sure you have Node.js v22+ and npm installed.

  3. Make sure you have Salesforce CLI v2.130.7+ installed. This version includes the UI Bundle plugin. Check your version with sf --version and update with sf update if needed.

  4. If you haven't already done so, authorize your hub org and provide it with an alias (myhuborg in the command below):

    sf org login web -d -a myhuborg
  5. Clone this repository:

    git clone https://github.com/trailheadapps/multiframework-recipes
    cd multiframework-recipes
  6. Create a scratch org and provide it with an alias (recipes in the command below):

    sf org create scratch -d -f config/project-scratch-def.json -a recipes
  7. Install dependencies, fetch the GraphQL schema, and build React Recipes:

    cd force-app/main/react-recipes/uiBundles/reactRecipes
    npm install
    npm run graphql:schema
    npm run graphql:codegen
    npm run build
    cd ../../../../..
  8. Deploy metadata and the UI bundle:

    sf project deploy start
  9. Assign the recipes permission set to the default user:

    sf org assign permset -n recipes
  10. Import sample data:

    sf data tree import -p ./data/data-plan.json
  11. Open the org and select the React Recipes app in App Launcher:

    sf org open

Setting up a Developer Edition Org

  1. Set up your environment. Follow the steps in the Quick Start: Lightning Web Components Trailhead project. The steps include:

    • Install Salesforce CLI
    • Install Visual Studio Code
    • Install the Visual Studio Code Salesforce extensions
  2. Make sure you have Node.js v22+ and npm installed.

  3. Make sure you have Salesforce CLI v2.130.7+ installed. This version includes the UI Bundle plugin. Check your version with sf --version and update with sf update if needed.

  4. Authorize your Developer Edition org and provide it with an alias (mydevorg in the command below):

    sf org login web -a mydevorg
  5. Clone this repository:

    git clone https://github.com/trailheadapps/multiframework-recipes
    cd multiframework-recipes
  6. Install dependencies, fetch the GraphQL schema, and build React Recipes:

    cd force-app/main/react-recipes/uiBundles/reactRecipes
    npm install
    npm run graphql:schema
    npm run graphql:codegen
    npm run build
    cd ../../../../..
  7. Deploy metadata and the UI bundle:

    sf project deploy start
  8. Assign the recipes permission set to the default user:

    sf org assign permset -n recipes
  9. Import sample data:

    sf data tree import -p ./data/data-plan.json
  10. Open the org and select the React Recipes app in App Launcher:

    sf org open

Local Development

Start the Vite development server with hot module replacement:

npm run dev

Build the app for production:

npm run build

Preview the production build locally:

npm run preview

Testing

Run unit tests (Vitest + React Testing Library):

npm test

Run with coverage:

npm run test:coverage

Run end-to-end tests (Playwright):

npx playwright install chromium
npm run build:e2e
npm run test:e2e

Optional Installation Instructions

This repository contains several files that are relevant if you want to integrate modern web development tools into your Salesforce development processes or into your continuous integration/continuous deployment processes.

Code formatting

Prettier is a code formatter used to ensure consistent formatting across your code base. To use Prettier with Visual Studio Code, install this extension from the Visual Studio Code Marketplace. The .prettierignore and .prettierrc files are provided as part of this repository to control the behavior of the Prettier formatter.

Code linting

ESLint is a popular JavaScript linting tool used to identify stylistic errors and erroneous constructs. The apps use ESLint with TypeScript and framework-specific plugins.

Pre-commit hook

This repository comes with a package.json file that makes it easy to set up a pre-commit hook that enforces code formatting and linting by running Prettier and ESLint every time you git commit changes.

To set up the formatting and linting pre-commit hook:

  1. Install Node.js if you haven't already done so.
  2. Run npm install in your project's root folder to install the ESLint and Prettier modules.

Prettier and ESLint will now run automatically every time you commit changes. The commit will fail if linting errors are detected. You can also run the formatting and linting from the command line using the following commands (check out package.json for the full list):

npm run lint

About

A collection of easy-to-digest code examples for React on Salesforce Platform

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors