Sliced Bread in a Nutshell

Introduction #

Thanks for diving into Sliced Bread. This article has been written to be as low-tech and accessible as possible. It does include some SQL snippets however, as we believe this will be a very comfortable language for most readers and it explains some of the concepts well. In the actual app you will not need to write any SQL. It’s all drag-and-drop.

Example #

There’s nothing that explains something better than a good example. In this article we’ll work on a Bulk DML problem. Imagine an org with an Employee custom object:

First NameLast NameDeptBirthday
EdwardStamosFIN1971-05-21
CaroleWhiteHR1982-11-01

This custom object is from ancient history and we want to get rid of it and move the birthday data to the standard Birthday field on Contact. The object contains more than 100,000 records so doing it manually is not an option. Downloading and uploading it with a data loader and doing data transformation in Excel is not an option either. It would take a lot of time still and downloading data that contains personally identifiable data is not approved by our compliancy offer and generally an unsafe idea.

Data Model #

As with any app, the data model is the basis so let’s look at that first. Sliced Bread contains only 3 objects.

Bread #

Bread represents a large body of data. For our example the bread represents a query:

select Id, First_Name__c, Last_Name__c, Department__c, Birthday__c 
from Employee__c

Slice #

Slice brings a full staging area to Salesforce. Each self-respecting ETL should do most of its work in a staging area and should only at the end hit the actual database. This is even more important with Salesforce, because of its trigger-happy nature. Each slice represents a bundle of related data. There are 3 ways to store information on Slice:

  1. Raw Data will contain the slice data in it’s original raw form.
  2. Salesfore Custom Fields can be added to Slice if you want to get “Salesforcey” with certain pieces of information, e.g. include them in list views or reports.
  3. But they can also be virtual fields, which are fields that fully live in Sliced Bread. The big advantage of virtual fields is that they travel really well. When you want to move a recipe to another org, then that will be seemless with virtual fields. If you take the Salesforce custom field route, then you will need to deploy these fields seperately. Mixing custom and virtual fields is possible.

Recipe Version #

Recipe Version contains the recipe for how a breads flows through the 4 phases of Sliced Bread.

Phases #

1. Slice #

Slice is the first phase in a Sliced Bread process. It is about taking a large body of data and slicing it into staged bundles of related data: slices. Slicing an actual bread into slices is a metaphor that works well. This part we had to solve off-platform on AWS. To keep true to our promise of 100% native, we implemented each of our four slicers with two guidelines in mind: (1) they are not allowed to touch a file system and (2) we like our slicers to be as dumb as possible. The slicers are:

  1. Generate Slices We don’t have favourites, but if we would, this is probably the one as it’s incredibly dumb. Just the way we like it. All it does is generate a number of empty slices. Empty slices are useful for generating data with Sliced Bread.
  2. Slice File Into Lines This slicer downloads a file from Salesforce and then creates a slice for each line in the file. Raw Data will contain the line as-is with possibly also a header added for context. Use this slicer for processing CSV files or any other file format that bundles data in single lines.
  3. Slice Data Into Records This slicer executes a SOQL query on Salesforce and then creates a slice for each record in the result set. Use this slicer if you want to perform bulk DML.
  4. Slice Data Into Buckets This slicer will execute a SOQL query and gets the full result set. It will then start grouping the results into buckets and calculate sum, min, max, count, count distinct, etc. Per bucket it will create a slice. This slicer turned out not that dumb, but we still love her to bits tough. Also this slicer – just like the others – doesn’t touch the file system in any way, not even temporary file storage or a database.

In our Bulk DML example the Slice Data Into Records slicer is used. A slice is created for each resulting record. The record is initially stored in Raw Data in CSV format:

Slice 1 Raw Data:

Id,First_Name__c,Last_Name__c,Dept__c,Birthday__c
a023O000007wu2z,Edward,Stamos,FIN,1971-05-21

Slice 2 Raw Data:

Id,First_Name__c,Last_Name__c,Dept__c,Birthday__c
a023O000007wu30,Carole,White,HR,1982-11-01

2. Extract #

Extract, Transform and Load are fundamentally different to the Slice phase in two ways: (1) Slice is the key object, not Bread. (2) They run fully on Salesforce.

Extract is about taking the slice from the bread and putting it on a plate to be able to start working with the information. Or in more technical terms: it is about parsing raw data and making data processable by storing it into Slice fields. Sliced Bread currently includes two parsers: CSV and JSON.

In our example the CSV parser is used to extract data into 5 new virtual fields:

(Virtual) FieldSlice 1Slice 2
Employee Ida023O000007wu2za023O000007wu30
First NameEdwardCarole
Last NameStamosWhite
DepartmentFINHR
Birthday1971-05-211982-11-01
Raw DataSee aboveSee above

3. Transform #

In the Transform phase we start turning our slice of bread into a delicious sandwich by adding tomato, cucumber, avocado or however you like your sandwich. In this phase you gather and calculate all required extra data and store that data in yet more Slice fields. To do so, Sliced Bread offers three rule types:

  1. Query Use this to go into Salesforce and gather related information.
  2. Formula Use this to calculate new data based on previously extracted or transformed data. Formulas work exactly the same in Sliced Bread as in Salesforce. We added a few extra functions, which we felt were essential. For example RANDLASTNAME which is useful when generating data.
  3. Validate Use this to automatically validate data. Sliced Bread validation rules work the same as Salesforce validation rules, except that we added one nifty feature. You can specify the status of the Slice if the validation fails: Failed if something went wrong that needs troubleshooting, Paused if you want a user to do something or Discarded if you don’t care about this Slice anymore.

In our example there are two transform challenges. The first one is that Contact has a different convention for departments. We can solve that by adding a formula rule that stores the result in a new virtual field Contact Department:

CASE(Department, 'FIN', 'Finance', 'HR', 'Employee Success')

The second transform challenge is to find the Contact record that goes with the Birthday record. We can solve this by adding a query rule that finds the Contact record by executing the query below and stores the result in a new virtual field Contact.

SELECT Id 
FROM Contact
WHERE FirstName = :Slice.First_Name
AND LastName = :Slice.Last_Name
AND Department = :Slice.Contact_Department

After running these rules, the slices now looks like:

(Virtual) FieldSlice 1Slice 2
Contact Id0033O00000rM7wP0033O00000rME3y
Contact DepartmentFinanceEmployee Success
Employee Ida023O000007wu2za023O000007wu30
First NameEdwardCarole
Last NameStamosWhite
DepartmentFINHR
Birthday1971-05-211982-11-01
Raw DataSee aboveSee above

Ready To Load #

Ready To Load is actually not a phase. We’re still in the Transform phase, but at the very end. So what’s this section doing here then? Well, there is something very magical about this point in the process. On the one hand a lot of work has happened with all the slicing, extracting and transformation completed. But on the other hand nothing really happened. Your org data hasn’t been touched at all, only the staging area. If you don’t feel comfortable, just work on the recipe a bit more and try again. You are not going to eat every sandwich you see right? You first have a good look if it looks absolutely perfect before you start eating it. Your body (and your org) is your temple.

At this point we could theoretically predict very precisely how the Load phase will modify your org. And yes, we actually do go through the trouble of calculating that prediction in the form of a load plan, both in summary form on the Bread-level as very detailed at the Slice level. So you’ll be able to make that go / no-go decision super well informed.

There’s one important note here that we don’t want any confusion about. When making the load plan, we don’t take into account Salesforce customizations. The load plan is purely based on the Sliced Bread recipe.

4. Load #

In the Load phase we finally start updating your org by performing one or more create, update, upsert and delete operations on one or more objects.

In our example we perform two load operations. First we move the birthday value:

UPDATE Contact
SET Birthday = :Slice.Birthday
WHERE Id = :Slice.Contact_Id

And secondly we can delete the Employee record now:

DELETE FROM Employee
WHERE Id = :Slice.Employee_Id

Done #

We’re done! All birthdays have been moved to Contact where they belong and the Employee object is empty now. Salesforce data has been sliced into manageable slices, extracted into processable fields, transformed to include all information needed and then loaded into your org. We went from a whole bread to more than 100,000 delicious sandwiches enjoyed by your org.

First Rule Of Sliced Bread #

When using the Recipe Builder, it’s important to understand the first rule of Sliced Bread:

Fields on Slice are never modified and rules that have no room to store their output will be skipped.

Altough this property may sound restrictive, we think this is the secret sauce of what makes Sliced Bread highly productive. It allows for easy rule chaining, for example trying multiple ways of finding a Contact and if that doesn’t work, creating one. Have a look at some examples to better understand how this works.

Next Steps #

For the ones that just want to get started now, go for it. We tried our utmost to make everything as intuitive, Salesforcey and easy to use as possible. Enjoy using Sliced Bread!

Copyright © 2024 all rights reserved, powered by Sliced Bread Software B.V.