Salesforce data migration between organizations
This documentation will help you migrate settings between Salesforce organizations. For example, from a Sandbox environment to a production one. First, you need to install the package on a working environment (Production).
After installing the InCountry package, follow the steps below:
Navigate to Setup > Administration > Users > Permission Sets.
Assign the
InCountry User
,InCountry Admin
andInCountry Community User
permission sets to appropriate Salesforce users.Navigate to Setup > Settings > Identity > Identity Provider.
Click Enable Identity Provider.
Click Save.
Navigate to Setup > Translation Language Settings.
Click Enable.
note
To migrate metadata between Salesforce organizations, we can use Workbench (a manual Tool) or SFDX CLI commands.
Workbench (Tool)
The process of migrating data through Workbench is comprised of the following steps:
Retrieval of metadata
Deployment of metadata
Retrieving metadata
Navigate to https://workbench.developerforce.com/login.php.
Salesforce uses the concept of sandbox and production organizations. The sandbox has the
test.salesfoece.com
domain. Production has thelogin.salesforce.com
domain.Choose the environment: Production or Sandbox.
Check the I agree to the terms of service box.
Click Login with Salesforce and fill in credentials for the Salesforce organization from which you want to migrate the settings.
In the navigation menu, click Migration.
Click Retrieve.
Click Choose file.
Select package.xml. The package.xml file will be populated with the following metadata from your organization:
Certificate
CspTrustedSite
CustomApplication
CustomLabels
CustomMetadata
CustomTab
FlexiPage
GlobalValueSet
GlobalValueSetTranslation
Layout
ListView
PermissionSet
PermissionSetGroup
RemoteSiteSetting
Report
ReportType
CustomField
CustomObject
CustomObjectTranslation
Click Next.
Click Retrieve.
Once the status changes to Success, click Download ZIP File.
Deploying metadata
Navigate to https://workbench.developerforce.com/login.php.
Salesforce uses the concept of sandbox and production organizations. The sandbox has the
test.salesfoece.com
domain. Production has thelogin.salesforce.com
domain.Choose the environment: Production or Sandbox.
Check the I agree to the terms of service box.
Click Login with Salesforce and enter credentials for the Salesforce organization to which you want to migrate the settings.
In the navigation menu, click Migration.
Click Deploy.
Click Choose file and select the downloaded zip file.
Check the Rollback On Error box.
Click Next.
Click Deploy.
Once the status is updated to Success, the settings will migrate to a new organization.
After that, you need to fill records in our Custom Metadata type InCountryRestApiEndpoint
.
Navigate to Setup.
Search for Certificate and Key Management. We can see all certificates which we have uploaded on the previous Salesforce organization.
Click on gear in the upper right corner and click Setup in the dropdown menu.
Search Custom Metadata Types.
Click Manage Records opposite to
InCountryRestApiEndpoint
.Fill in certificate names in fields
CertificateNameApi
,CertificateNameBatch
,CertificateNameRest
,CertificateNameServerless
for the right countries. The example illustrates the population of settings for Saudi Arabia.Сheck the Endpoint box, change if necessary.
Click Save.
Above we have described the steps for manual migration using third-party tools. Next, we will describe the steps using the tools provided by Salesforce. These tools are the SFDX cli commands.
SFDX CLI command
First, you need to download SFDX CLI and install https://developer.salesforce.com/tools/sfdxcli.
Retrieving metadata (via package.xml)
Create an SFDX Project with the manifest file (from Webstorm for example) or open the terminal in the SFDX project folder.
Find or create folder with name “manifest” in root SFDX project folder
Copy package.xml file and paste(replace if it needed) in manifest folder
The package.xml file will receive the following metadata from your organization:
Certificate
CspTrustedSite
CustomApplication
CustomLabels
CustomMetadata
CustomTab
FlexiPage
GlobalValueSet
GlobalValueSetTranslation
Layout
ListView
PermissionSet
PermissionSetGroup
RemoteSiteSetting
Report
ReportType
CustomField
CustomObject
CustomObjectTranslation
Run
sfdx auth:web:login --instanceurl https://login.salesforce.com
. Theinstanceurl
value can take https://test.salesforce.com (Sandbox) or a custom domain.Fill in credentials of the Salesforce organization from which you want to migrate the settings.
Run
sfdx force:source:retrieve -x manifest/package.xml -u username
(from the organization which you want to migrate the settings).
Deploying metadata (via package.xml)
Run
sfdx auth:web:login --instanceurl https://login.salesforce.com
. Theinstanceurl
value can take (Sandbox) or custom domain.Fill in credentials of the Salesforce organization to which you want to migrate the settings.
Run
sfdx force:source:deploy -x manifest/package.xml -u username
(to which you want to migrate settings).
Retrieving metadata (without package.xml)
Create an SFDX Project with the manifest file (from Webstorm for example) or open the terminal in the SFDX project folder.
Update the package.xml file in the manifest folder on our file.
Run
sfdx auth:web:login--instanceurl https://login.salesforce
. Theinstanceurl
value can take https://test.salesforce.com (Sandbox) or a custom domain.Fill in credentials of the Salesforce organization from which you want to migrate settings.
The SFDX command will retrieve the following parameters:
Certificate
CspTrustedSite
CustomApplication
CustomLabels
CustomMetadata
CustomTab
FlexiPage
GlobalValueSet
GlobalValueSetTranslation
Layout
ListView
PermissionSet
PermissionSetGroup
RemoteSiteSetting
Report
ReportType
CustomField
CustomObject
CustomObjectTranslation
Run
sfdx force:source:retrieve -m "Certificate, CspTrustedSite, CustomApplication, CustomLabels, CustomMetadata, CustomTab, FlexiPage, GlobalValueSet, GlobalValueSetTranslation, Layout, ListView, PermissionSet, PermissionSetGroup, RemoteSiteSetting, Report, ReportType, CustomField, CustomObject, CustomObjectTranslation" -u username (from organization from which you want to migrate the settings).
Deploying metadata (without package.xml)
Run
sfdx auth:web:login --instanceurl https://login.salesforce.com
. Theinstanceurl
value can take https://test.salesforce.com (Sandbox) or a custom domain.Fill in credentials of the Salesforce organization to which you want to migrate the settings.
Run the following command:
sfdx force:source:deploy -m "Certificate, CspTrustedSite, CustomApplication, CustomLabels, CustomMetadata, CustomTab, FlexiPage, GlobalValueSet, GlobalValueSetTranslation, Layout, ListView, PermissionSet, PermissionSetGroup, RemoteSiteSetting, Report, ReportType, CustomField, CustomObject, CustomObjectTranslation" -u username (to which you want to migrate the settings).
After that, you need to fill records in our Custom Metadata type InCountryRestApiEndpoint
.
Navigate to Setup.
Search Certificate and Key Management.
We can see all certificates which we have on the previous Salesforce organization.
Open in a new tab setup.
Search Custom Metadata Types.
Click Manage Records next to
InCountryRestApiEndpoint
.Fill in the certificate names in fields
CertificateNameApi, CertificateNameBatch, CertificateNameRest, CertificateNameServerless
for the right countries.Сheck the Endpoint field and change it if necessary.
Click Save.
note
To migrate data between Salesforce organizations, we can use the Salesforce Inspector extension for Google Chrome or SFDX CLI Commands.
Below is an example of how to migrate Policy and PII Fields for a new Organization.
Salesforce Inspector extension for Google Chrome
First, you need to install the Salesforce Inspector extension for Google Chrome.
Retrieving PII fields Data
Log in to the organization from which you want to migrate data.
Click Salesforce Inspector.
Click Export Data.
Paste the values below into the export query:
select testIncountry1__IsCountryField__c, testIncountry1__Field_name__c, testIncountry1__IsLookup__c, testIncountry1__LookupRelationshipName__c, testIncountry1__LookupRequiredToSelectFields__c, testIncountry1__LookupObjectApiName__c, testIncountry1__NeedHash__c, testIncountry1__Object_name__c, testIncountry1__Reference_field__c, testIncountry1__Reference_order__c, testIncountry1__SearchKey__c, testIncountry1__Validation_strategy__c from testIncountry1__Object_relationship_fields__c
Click Export. After that, you should get some result.
Click Copy (CSV) in the Export result section.
Deploying PII fields Data
Log in to the organization to which you want migrate data.
Click Salesforce Inspector.
Click Import Data.
Choose the
testIncountry1__Object_relationship_fields__c
object.Select Format CSV and paste data.
Click Import.
Once all records are imported successfully, data will be migrated to a new organization.
Retrieving Policy Data
Log in to the organization from which you want to migrate data.
Click Salesforce Inspector.
Click Export Data.
Paste the values below into the export query:
select testIncountry1__Behavior__c, testIncountry1__Country__c, testIncountry1__Object_name__c, testIncountry1__Country_field__c, testIncountry1__CountryFieldValue__c, testIncountry1__Type__c from testIncountry1__Object_relationship__c
Click Export. After that we are getting some result.
Click Copy(CSV) in the Export result section.
Deploying Policy Data
Log in to the organization to which you want to migrate data.
Click Salesforce Inspector.
Click Import Data.
Choose the
testIncountry1__Object_relationship__c
object.Select Format CSV and paste data.
Click Import.
Once all records are imported successfully, data will be migrated to a new organization.
SFDX CLI Commands
Retrieving PII fields Data
Create an SFDX Project with the manifest file (from Webstorm for example) or open a terminal in the sfdx project folder.
Run
sfdx auth:web:login --instanceurl https://login.salesforce.com
. Theinstanceurl
value can take https://test.salesforce.com (Sandbox) or a custom domain.Fill in credentials for the Salesforce organization from which you want to migrate settings.
Run the following command:
sfdx force:data:tree:export -u username (from orgatization from which to migrate the settings) --query "select testIncountry1__IsCountryField__c, testIncountry1__Field_name__c, testIncountry1__IsLookup__c, testIncountry1__LookupRelationshipName__c, testIncountry1__LookupRequiredToSelectFields__c, testIncountry1__LookupObjectApiName__c, testIncountry1__NeedHash__c, testIncountry1__Object_name__c, testIncountry1__Reference_field__c, testIncountry1__Reference_order__c, testIncountry1__SearchKey__c, testIncountry1__Validation_strategy__c from testIncountry1__Object_relationship_fields__c" --outputdir sfdx-out --plan
After that, the folder sfdx-out will appear in the project.
Deploying PII fields Data
Run
sfdx auth:web:login --instanceurl https://login.salesforce.com
. Theinstanceurl
value can take https://test.salesforce.com (Sandbox) or a custom domain.Fill in credentials for the Salesforce organization to which you want to migrate settings.
Run the following command:
sfdx force:data:tree:import -u username (which to migrate the settings) --plan sfdx-out/testIncountry1__Object_relationship_fields__c-plan.json
Once all records are imported successfully, data will be migrated to a new organization.
Retrieving Policy Data
Create an SFDX Project with the manifest file (from Webstorm for example) or open a terminal in the sfdx project folder.
Run
sfdx auth:web:login --instanceurl https:login.salesforce.com
. Theinstanceurl
value can take https://test.salesforce.com (Sandbox) or custom domain.Fill in credentials for the Salesforce organization from which you want to migrate settings.
Run the following command:
sfdx force:data:tree:export -u username (from orgatization from which you want to migrate the settings) --query "select testIncountry1__Behavior__c, testIncountry1__Country__c, testIncountry1__Object_name__c, testIncountry1__Country_field__c, testIncountry1__CountryFieldValue__c, testIncountry1__Type__c from testIncountry1__Object_relationship__c" --outputdir sfdx-out --plan
After that, the folder sfdx-out
will appear in the project.
Deploying Policy Data
Run
sfdx auth:web:login --instanceurl https:login.salesforce.com
. Theinstanceurl
value can take (Sandbox) or a custom domain.Fill in credentials for the Salesforce organization to which you want to migrate the settings.
Run the following command:
sfdx force:data:tree:import -u username (to which you want to migrate the settings) --plan sfdx-out/testIncountry1__Object_relationship__c-plan.json
Once all records are imported successfully, data will be migrated to a new organization.