Salesforce Commerce Cloud Connector

The React Storefront headless ecommerce connector for Salesforce Commerce Cloud.

This guide covers how to get up and running with the Salesforce Commerce Cloud Connector. For information on connectors in general and how to write your own connector refer to the React Storefront Connectors documentation.


You will need a Salesforce Commerce Cloud site and API client setup to try out the connector.

Running Locally

Create a new React Storefront app using version 8.14.0 or later:

npm create react-storefront@^8.014.0 my-sfcc-app

Next cd into your created application and install the Salesforce Commerce Cloud connector:

cd my-sfcc-app
npm install react-storefront-salesforce-commerce-cloud-connector

Next configure the SITE_ID, SHORT_CODE, ORGANIZATION_ID, and CLIENT_ID environment variables in .env file to point to your Salesforce Commerce Cloud site and API client. See .env.sample file as an example of adding env variable via dotenv. You can also check this guide to get more info about Node.js Environment Variables. For example, your .env file may look like:

Finally set the connector in your next.config.js file. By default this file is set to use the react-storefront/mock-connector as shown below:

module.exports = withReactStorefront({

  // ... Some code

  connector: 'react-storefront/mock-connector',

  // ... More code

Change this line to use the react-storefront-salesforce-commerce-cloud-connector as shown below:

module.exports = withReactStorefront({

  // ... Some code

  connector: 'react-storefront-salesforce-commerce-cloud-connector',

  // ... More code

Now you can run your project locally,

npm start

And then visit in your browser.

Deploying to Layer0

The front-end React Storefront can be hosted anywhere that supports Node and Express but it works great on Layer0. You can try Layer0 for free by signing up here. Once you have an account you can deploy it by running layer0 deploy:

layer0 deploy

Refer to the Layer0 deployment guide for more information.

Configure Static Prerendering in Layer0

The connector has a built-in prerender module which fetches all category routes and the first ten products for each category by default. This will ensure the first page your users land on will be cached.

You simply need to add these lines to your routes.js file:

const { getPrerenderUrls } = require('react-storefront-salesforce-commerce-cloud-connector')

module.exports = new Router().prerender(getPrerenderUrls)
// ...the rest of your router

The getPrerenderUrls function takes an options object as it's only parameter.

For example, you could fetch products from each category with the following options:

{ sort: 'most-popular', offset: 0, limit: 13 }

More info on how to customize your routes to prerender here