Showing posts with label forcecode. Show all posts
Showing posts with label forcecode. Show all posts

Monday, July 27, 2020

Salesforce Metadata Deployment

Salesforce Metadata Deployment

What are metadata?

Let's understand this through a simple example. Imagine you are a Salesforce Admin and need to create a new field in Account object. Then, you log into your sandbox, navigate to Object Manager, and create your field there. Then what happens? Have you think beyond that? Then the magic happens. Salesforce has configuration file for each and every object. It updated the configuration file for Account object and adds an entry under fields for your new field along with its configs.

Similarly, Salesforce maintain configuration files for almost all the component types. These configuration files are called metadata files. When you log into Salesforce, its back-end reads metadata files and renders the UI accordingly.

How metadata deployment works

Now we know what is metadata and what happens when you create a field. In other words now we know two ways of creating a field in a Salesforce Object.

  • Log into the Salesforce and create the field using provided UI.
  • Directly update the metadata file and add configuration for the new field.

The first approach we already know and follow. The metadata deployment uses the second approach. It replaces the existing metadata file with an updated metadata file. Following sequence of steps are followed when doing metadata deployment. (Scenario : Create 5 new fields on Account Object)

  1. Log into the Sandbox A and create new fields.
  2. Fetch Account.object metadata file from Sandbox A.
  3. Deploy Account.object metadata file into Sandbox B.

Now, log into Sandbox B, you can see newly created fields are there. That's it. How easy. Yes, it's always easy to say rather than doing. But fortunately, now a days a lot of tools out there. These tools do all the hard work for us. So doing it is as easy as 1-2-3.

Let's go deep into each step.

Log into the Sandbox A and create new fields

No need of talking about this. If you do not know this step, you will have nothing to deploy. You are done. Go and have a rest. This post is about deployment; not about development. :-)

Fetch Account.object metadata file from Sandbox A

Deploy Account.object metadata file into Sandbox B

Most of the tools available, supports both fetching and deploying. Please have a look at the following list of tools and its references.

  • Ant Migration Tool

    Visit the official page for instructions.

    Since Ant Migration Tool is based on JAVA it supports any platform and very flexible to use. It supports destructive changes as well. Based on Command Line Interface.

  • Salesforce CLI

    Visit the official page for instructions.

    Available for MacOS, Windows, and Debian/Ubuntu distributions. By the mean of the name, it's based on Command Line Interface.

In addition to above mentioned tools, there are many around the internet. Also there are VS Code extensions such as SFDX, ForceCode, and etc. Select your favourite tool, enjoy deployment, and get rid of repetitive tasks.

Advantages of Metadata Deployment

Since it is source driven deployment(unlike Change Sets), you can introduce a version controlling system like git. It will allow multiple developers to work on the same component at the same time. Since you're using version controlling, it will avoid accidental overwriting of changes. You know who did what, and when.

Further, source code can be hosted in a server like BitBucket and deployments can be automated with pipelines. Your code(changes) will be maintained in a cetralized location.

Salesforce Metadata Deployment

Salesforce Metadata Deployment What are metadata? Let's understand this through a simple example. Imagine you are a Salesforce Admin an...