11 Days of Salesforce Storefront Reference Architecture (SFRA) — Day 9: Jobs
Tags: salesforce, sfcc, sfra
Published: 2020-05-20 06:12:19

---
title: 11 Days of Salesforce Storefront Reference Architecture (SFRA) — Day 9: Jobs
published: true
date: 2020-05-14 17:03:57 UTC
tags: salesforce,sfcc,sfra
series: 11 Days of Salesforce Storefront Reference Architecture (SFRA)
canonical_url: https://medium.com/perimeterx/11-days-of-salesforce-storefront-reference-architecture-sfra-day-9-jobs-6e108cca055e
---

### 11 Days of Salesforce Storefront Reference Architecture (SFRA) — Day 9: Jobs

![](https://cdn-images-1.medium.com/max/1024/1*5DM6isuhLHyZ-Vqjq78Q9A.jpeg)<figcaption>Photo by <a href="https://unsplash.com/@polarmermaid?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Anne Nygård</a> on <a href="https://unsplash.com/s/photos/job?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption>

There may come a time where we want to run code automatically and repeatedly on our storefront (think Linux cron job). Such a job could be to update a local database with values, import or export product catalogs or even update a local resource on our site. SFCC provides us with a wonderful and accurately named framework — the Jobs framework — that enables us to handle these tasks.

### Automate All the Things!

So what actually is an SFCC job? Well my young Padawan, an SFCC job is really a set of steps (actions) that are executed in order (flow) on a fixed time interval. Executing behind the scenes, jobs do not affect our storefront performance when running and are invisible to the user. Think of a job as a house-elf that does work for you while you sleep.

Jobs are managed in Business Manager under Administration -> Jobs. This is the central point for anything related to Jobs and also the prime focus of today’s post 🎉

### Creating a Job

A common (and repeated) task for every website is maintaining a site map that provides information about the site structure so search engines will know what to index. Such a task is probably not something you want to deal with manually on a regular basis, which makes it the perfect candidate for our first job:

1. Open your Business Manager and navigate to **Administration** > **Operations** >  **Jobs**.
2. Click on **New Job** (located at the top right corner).
3. Fill in the following details and click  **Create** :

- **ID** : SiteMapJob
- **Description** : A job to update the site map file.

4. As soon as the job is created you’ll be greeted with the job configuration page. This is where you can configure (among other things) the two most important properties of a job: when it runs ( **Schedule and History** ) and what it does ( **Job Steps** ):

![](https://cdn-images-1.medium.com/max/1024/1*jg0RoH6WwB_d88Mud5Vssw.png)<figcaption>Yay, Job configuration page 🎉</figcaption>

#### **_Creating the Job Steps_**

Steps are the heart of the Job creation process. It’s here that we tell the job what to do, in which order to run its steps and what is the step context (global, specific site, etc.). Let’s add the site map creation step:

1. Click on the **Job Steps**  tab.
2. Click on **Configure a step**.
3. Choose **CreateSiteMap,** enter the following details, and click  **Assign** :

- **ID** : SiteMapCreationStep
- **Description** : A job step to create the site map.

At this point, you might notice that while our new step is created, it is highlighted in red 😱. Do not fear, this is normal! A site map is, as its name suggests, scoped to a site. Our step, however, is currently scoped as **organization**.

4. Click on the blue **Organization** button on the top left corner of our step and change the _scope_ dropdown to **Specific Sites**. Check the site(s) you wish the job to run on and click  **Assign.**

![](https://cdn-images-1.medium.com/max/1024/1*P0kJ6aUAKTI6lNVDLRsw4g.png)<figcaption>MobileFirst will be the only site my job runs on.</figcaption>

**Scheduling The Job**

Now that we configured the “what” let's define the “when”:

1. Click on the **Schedule and History**  tab.
2. Check the **Enabled** checkbox. This defines our job as a scheduled one.
3. Change the **Trigger** drop-down from _Once_ to **Recurring Interval**.
4. Under **Every** set **Amount** to _1_ and **Interval** to _Days_. This triggers our new job once a day.

> 🐘 There are many other scheduling options you can set in this tab. You can have the job run only on specific days, you can have the interval to be minutes, hours years etc. and you can even set a start and end date for your job if you want to have it run in a specific time frame.

### Go Wild 🌈

With everything in place, let’s run our job and see its status!

On the top right corner, you should see a blue **Run Now** button. Click it and wait a few seconds. On the bottom of the page, under the **Job History** section you should see the result of running our job:

![](https://cdn-images-1.medium.com/max/1024/1*ADCaC760DsMkFV6B5xc_ug.png)<figcaption>The sweet taste of success 🍾</figcaption>

And there you have it! An automated job that will keep your sitemap fresh and updated, while letting you deal with much more important stuff.

If you liked this out-of-the-box job we created here, then you are in for a treat tomorrow as we are going to deep dive into the world of custom code job steps.

As always, looking forward to your comments either here or on [Twitter](https://twitter.com/fullstackj) 😎

* * *