11

Backup and Restore

Whilst Salesforce is fabulous at providing a platform and underlying data facility for working with customer data and custom data, consideration should be paid to how data can be backed up from and restored to the Salesforce platform. We’re going to investigate the various methods available to perform both data backup and data restore operations.

In this chapter, we’ll cover the following topics:

  • Methods for backing up and restoring data on the Salesforce Lightning Platform
  • AppExchange and external software that facilitates data backup and restoration

Before we get into the contents of this chapter, let’s be clear that we’re going to investigate backing up and restoring both data and metadata. Metadata is data that describes data and is the format your customizations to the Salesforce platform take. Data is the actual data stored in your Salesforce org for customers and opportunities.

Let’s begin our exploration of backup and restoration by investigating the methods available to us when working with data backup and restoration on the Salesforce platform.

Methods for backing up and restoring data on the Salesforce Lightning Platform

Before we jump into methods for backing up and restoring data, let’s elaborate on the two data definitions we’re covering in this chapter, namely data and metadata, as both are interacted with differently when it comes to backup and restoration. Let’s start with metadata.

Introduction to metadata

Metadata is data that describes data. When we think of an eXtensible Markup Language (XML) file, that essentially is a file with data (the values) and metadata (the tags). For example, see the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
  <firstname>Aaron</firstname>
  <lastname>Allport</lastname>
</person>

The code example shows a simple XML structure for a person with a first name and last name. Here, we can use the metadata (the person and the firstname and lastname tags) to infer that we are representing a person called Aaron Allport.

Salesforce represents the customizations to make to your instance as a set of metadata files. For example, a public group XML is represented as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Group xmlns="http://soap.sforce.com/2006/04/metadata">
    <doesIncludeBosses>true</doesIncludeBosses>
    <fullName>Packt</fullName>
    <name>Packt</name>
</Group>

Here, we can infer from the XML that there is a group called Packt that allows records shared with that group to be shared with managers of group members.

Salesforce represents the vast majority of customizations as XML, and as such, they can easily be extracted and stored.

Now that we have covered how metadata is used to describe data, and, indeed, its use for your customizations on the Salesforce platform, let’s now look at what data is.

What is data?

In the realm of Salesforce, data is defined as the record data for the standard objects you have customized and the custom objects you have created stored in your instance. Whereas the metadata for the contact record may define a field for FirstName, the value stored in that field for each record is the data of the record. When data is imported or exported from the Salesforce platform, it is usually represented in the Comma-Separated Value (CSV) format, where the first row of the file provides the fields and the following rows are the data for each record (with each record represented as a row in the file). Other formats are possible using some transformation logic with middleware and the like. An example CSV file would look like the following for exporting a couple of contact records::

Id,FirstName,LastName,Email
003abcdefghi123456,Aaron,Allport,[email protected]
003jklmnopqr789012,John,Smith,[email protected]

Having understood the difference between data and metadata, let’s question why we should back up data and metadata in the first place.

Why back up data and metadata?

Let’s quickly touch upon why backing up data and metadata is important. First, Salesforce doesn’t automatically back up your data for you. Therefore, if there were to be a situation in which a user or automated process accidentally caused an unintentional loss of data from your Salesforce instance, it would make sense to have a copy of data from which a restore operation could take place. It’s considered good practice to take regular backups of your data in case of unexpected data loss or in case a data export is required for business operational reasons.

Just like backing up your data is considered good practice, Salesforce offers the ability to back up your metadata, effectively allowing you to save most (but not all) of the configuration of your org. This is especially useful in the development of metadata changes from Salesforce sandbox environments, in addition to ensuring you keep a backup of your Salesforce environment configuration.

Now we’ve covered some scenarios for backing up data, let’s explore the various methods to export and import data and metadata. We’ll begin with backing up data.

Backing up data

Salesforce offers three platform-native ways to export your data. Whilst middleware can facilitate more advanced data retrieval and transformation, the relatively straightforward requirement to back up data can be facilitated using the following:

  • The Data Export service
  • Data Loader
  • Report Exports

Let’s explore each of these in turn, starting with the Data Export service.

The Data Export service

The Salesforce Data Export service can be used to export data from Salesforce on demand or a weekly or monthly basis. Available from the Salesforce setup menu under Data Export, it’s possible to include all the data in the Salesforce instance. The user who scheduled the export will receive an email when Salesforce has finished processing the export, containing a link to the zip file of the export, which contains a CSV file for each object of data.

Important note

Data Export is not possible in sandbox environments.

Now we’ve understood the Data Export service and how it facilitates backups of data, let’s turn to Data Loader.

Data Loader

The Data Loader application facilitates exports of the data contained within objects on a per-object basis, saving the contents of the export in CSV format. It’s entirely possible to choose the field data to include when configuring the export by specifying the Salesforce Object Query Language (SOQL) query for Data Loader to execute when running the export.

Important note

Data Loader doesn’t support exporting attachments.

As Data Loader requires the user to log in to Salesforce to perform actions on their behalf, the user exporting the data will therefore need read access to the records they are exporting. Bear in mind how permissions will affect the export. For example, the Organization-Wide Defaults (OWDs) being set to Private, with no other sharing configured, will mean that by default, only the records owned by the user will be included in the export.

With Data Loader covered, let’s now look at report exports.

Report Exports

Report Exports are probably the simplest and easiest way to export data from Salesforce but are contextual only to the data contained within the report. Essentially, when a report is run by a user, and that user has the Export Reports permission assigned to them through their profile or a permission set, they can choose to export the report using one of two options:

  • A formatted report, which exports to Excel (.xlsx) format only. This type of export includes headings and retains the report format as it appears at the time of initializing the export.
  • A Details Only report, which exports all report rows without any formatting. This format supports choosing an export file type, such as Excel (both .xls and .xslx) and CSV.

Report Exports are downloaded immediately upon invoking the export.

With the methods of exporting data now covered, let’s explore how to import data into the platform as a means of restoring data.

Importing data

To import data into the Salesforce platform natively, there are, of course, the APIs that we have covered in other chapters, such as the Bulk API. However, it’s worth briefly mentioning the Data Loader application and the Data Loader facility in the Salesforce user interface.

Importing data using the Data Loader application

Just as the Data Loader application can be used to export data from your Salesforce instance, it can also be used to import data. To do so, CSV files for the object data must be prepared in advance to serve as the data to be imported. When invoking the Data Loader application to import data, the columns of the CSV to be imported can be mapped to the fields of the object being imported.

Importing data using the Data Loader facility through the Salesforce user interface

Salesforce setup supports importing data into an object using a CSV file, much in the same way that the Data Loader standalone application does, including the mapping of columns for the destination object.

Now we’ve covered importing data, let’s move on to exporting metadata.

Backing up metadata

When it comes to backing up the metadata for a Salesforce instance, there are several methods that can be exploited to do so. These include the following:

  • Sandbox refreshes
  • Change sets
  • SFDX
  • The Ant Migration Tool

Let’s explore each of these in turn.

Sandbox refreshes

Probably the easiest way to back up metadata from your production Salesforce instance is by initiating a sandbox refresh. This facility either creates or refreshes a designated sandbox environment with a copy of the production metadata (but depending on the sandbox environment type, data may or may not be present).

With sandbox refreshes covered, let’s investigate change sets.

Change sets

Change sets are often the first way that many Salesforce administrators and developers learn to move selective metadata changes from a sandbox environment to the production environment. Change sets are non-developer friendly and essentially act as the de facto way for non-developers to move sets of metadata between Salesforce environments. Whilst most change set usage is for moving changes up into the production environment, change sets can also be used for moving changes from the production environment to a specific sandbox environment.

Having understood how change sets are used for selective metadata movement between environments, let’s touch upon Salesforce Developer Experience (SFDX).

SFDX

A developer-focused suite of command-line utilities, SFDX allows for metadata changes to be exported and imported from the production environment or any sandbox created from the production environment to which the user has login access. Knowledge of the specifics of SFDX usage is not important for the exam but it is useful to know that it can be used by developers to export metadata from Salesforce.

The Ant Migration Tool

Much like SFDX, the Ant Migration Tool is another command-line utility for moving your Salesforce metadata between a local directory and a Salesforce instance. Again, as with SFDX, the Ant Migration Tool can be used to move Salesforce metadata from a production environment to a local directory.

Now that we’ve explored backing up metadata, let’s move on to importing metadata.

Importing metadata

As you can probably imagine by now, all methods besides the sandbox refresh process can be used to import metadata as a way of restoring the metadata to a Salesforce instance. Let’s start with change sets.

Change sets

By capturing a selected set of metadata artifacts and moving them from one Salesforce environment to another, change sets can be used to restore a set of changes from one environment to another. Imagine a Salesforce environment refreshed from production by accident – if there were another Salesforce environment that contained the updated set of metadata artifacts, then change sets could be used as a means of performing the metadata restoration.

Let’s now explore SFDX as a means to restore metadata.

SFDX

With SFDX, it is possible to use a local filesystem or source code repository to store the metadata files. This is therefore a suitable means from which to perform selective metadata restoration activities to a specific environment from a local file store or repository.

With SFDX re-visited, let’s briefly touch on the Ant Migration Tool.

The Ant Migration Tool

Again, much like SFDX, the Ant Migration Tool can be used to perform metadata restorations from local file directories to specific Salesforce environments, notably production in the case of a restoration scenario.

Now that we’ve explored importing metadata, let’s now investigate AppExchange and external software that facilitates backup and restoration of data and metadata.

AppExchange and external software that facilitates data backup and restoration

When working with data backup and restoration on the Salesforce platform, naturally, there are developers and software vendors that have explored how far data backup and restoration extend beyond the native platform offerings provided by Salesforce. As is the norm for many use cases on the platform, such as industry-specific extensions to business logic for a given industry vertical, there are also AppExchange packages and full-blown external software that support data backup and restore operations.

For example, Salesforce Backup and Restore is a paid add-on to your Salesforce subscription that facilitates regular, automatic backups of the data and metadata held within your Salesforce instance. Those backups can then be used to restore data and metadata to your Salesforce instance as required, irrespective of the operations that necessitated the action in the first place, such as human error.

There are AppExchange packages that facilitate the automated backup and restoration of Salesforce data and metadata, often to off-platform facilities. These incur a separate charge to the Salesforce subscription, as they involve contracting with a different software vendor. This then allows operations to be performed using the AppExchange package as a conduit for the various operations to and from that external platform, such as data backup and restoration. To learn more about AppExchange packages that facilitate the backup and restoration of data and metadata to and from the Salesforce platform, please read more at https://appexchange.salesforce.com/appxSearchKeywordResults?keywords=backup%20and%20recovery.

Next, there are full-blown external software packages that support data and metadata backup and restoration, often integrating with SFDX for metadata operations. An intricate understanding of these software packages is beyond the scope of the exam (and therefore this book), but they all automate and facilitate automated sandbox provisioning and backup and restoration of data and metadata, and often integrate with automated workflows as part of a Continuous Integration/Continuous Deployment (CI/CD) pipeline.

Let’s now summarize what we’ve covered in this chapter.

Summary

In this chapter, we looked at the ways in which you can back up and restore both data and metadata when working with the Salesforce platform. We started by breaking down what the difference between data and metadata is before moving on to the tools available from a native or platform standpoint when it comes to backing up and restoring metadata and data.

Next, we moved on to looking at AppExchange and external software that facilitates backup and restoration, covering what they do to facilitate and even speed up this task. Lastly, we looked at some best practices when exporting and importing data.

In the next chapter, we’ll explore Territory Management to conclude our learning material.

Practice questions

Test your understanding of the concepts covered in this chapter by attempting the following practice questions:

  1. Which Salesforce feature allows for selected metadata changes to be migrated from one environment to another?
  2. What is the name of the standalone application that facilitates data imports and exports to and from the Salesforce platform?
  3. Which report export format supports CSV, XLS, and XLSX?
  4. Which facility allows for monthly backups?
  5. What format is the file from a monthly backup?
  6. What is metadata?
  7. What metadata backup facility is used to create a production-like instance of Salesforce?
  8. Which two metadata backup and restore technologies work with local or source-controlled copies of metadata?
  9. What does CSV stand for?
  10. In a CSV file, the first row of data is the what?

Answers

How did you get on answering the practice questions? Check your answers here:

  1. Change sets
  2. Data Loader
  3. Details Only
  4. The Data Export service
  5. A zip file containing several CSVs
  6. Data that describes data
  7. Sandbox refreshes
  8. SFDX and the Ant Migration Tool
  9. Comma-Separated Value
  10. The field names to which the values in the following rows pertain

Further reading

For further information about the concepts and topics covered in this chapter, please refer to the following resources:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.97.64