Showing posts with label SalesforceDX CLI. Show all posts
Showing posts with label SalesforceDX CLI. Show all posts

Wednesday, 22 November 2017

Salesforce DX: Test Data migration using Salesforce DX

Here I am going to show case a small POC of Data migration using Salesforce DX, its really easy to use, and the process where you want to maintain the test data in different-different Sandbox, then Salesforce DX is for you.


So lets get started,
Before going further, if you have not installed Salesforce DX in your system and please go ahead and install it you system.

Here is the Trailhead link where you can find link to install and get to know more about SalesforcDX.



After installing open the git bash and check whether SalesforceDX got successfully installed or not.

So let me explain you a bit about this process using dx, here we will use two sandbox, one from where we will export the data and the other is the destination sandbox where we will import the data, now this is the first time process, where we are exporting the data from one sandbox, but if its recurring process then we will have the data in JSON format in our local machine, so we just need to export it to other sandboxes.

Please enter

$ sfdx force

If it show the cloud image made up of DX then its installed, now we will create a project first.

$ sfdx force:project:create -n web //create project, its not necessary you can skip this one also

//Add a new sandbox , on hitting this command it will ask you to login to you sandbox and authorize
$ sfdx force:auth:web:login --setalias my-sandbox --instanceurl https://salesforce.com

//after this do the same thing again and add another sandbox.
//Now if you want to check how many orgs you have added you can by below command
$ sfdx force:org:list

//you have to define an org as default to so that dx will fetch the data from that org. use below for the same
$ sfdx force:config:set defaultusername=abhi@sfdx.com.cloudy --global

//now export the data, here we are exporting only account data, but you can do allot more then this
$ sfdx force:data:soql:query --query "Select Id, Name From Account"

If you'll check that file that DX has created will have the content something like below


{
    "records": [
        {
            "attributes": {
                "type": "Account",
                "referenceId": "AccountRef1"
            },
            "Name": "Sinclair Community College"
        },
        {
            "attributes": {
                "type": "Account",
                "referenceId": "AccountRef2"
            },
            "Name": "The Institute of Electrical and Electronics Engineers, Inc."
        },
        {
            "attributes": {
                "type": "Account",
                "referenceId": "AccountRef61"
            },
            "Name": "TestLastName"
        }
    ]
}


In the command prompt you'll be able to see the data count as well.

Now to import the data to another sandbox, you just have to hit another command, as its so easy so here are the things need to consider before hitting the command

1. Define the correct source path of the JSON file.
2. Provide the correct sanbox username.
3. Sandbox should be from the list of the sandbox added in the DX.

//to import data to sandbox
$ sfdx force:data:tree:import --targetusername abhi-tripathi@sfdx.com.cloudy--plan sfdx-out/export-demo-Account-plan.json

Your command prompt


















Woohoo!! you have just performed the data migration using SalesforceDX

Here are some links that will be helpfull

https://trailhead.salesforce.com/trails/sfdx_get_started/modules/sfdx_dev_model

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_test_data_example.htm

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm

https://trailhead.salesforce.com/trails/sfdx_get_started/modules/sfdx_app_dev

https://trailhead.salesforce.com/trails/sfdx_get_started/modules/sfdx_travis_ci

https://www.youtube.com/watch?time_continue=1596&v=exZ3TICOzd8

Thanks you!!

Friday, 14 July 2017

Get Started with Setup of SalesforceDX, using Salesforce DX CLI #sfdx

Summer ’17 contains a beta release of Salesforce DX, Salesforce DX provides you with an integrated, end-to-end lifecycle designed for high-performance agile development. And best of all, we've built it to be open and flexible so you can build together with tools you love.


So here we are going to start the setup of SalesforceDX

Step 1 : Create SalesforceDX trial org or Salesforce Dev Hub Trial Org, here is the link


         https://developer.salesforce.com/promotions/orgs/dx-signup

Step 2 : Enable the Dev hub in your org, perform below steps


Step 3 : Create a SalesforceDX user or you can use System admin user also, if your user is not a System admin, then create a permission set and assign the permission set to the salesforceDX user, permission set will have below permissions



Step 4 : Install SalesforceDX CLI

here is the link to download
After downloading the SalesforceDX CLI, install it.


After installing, it will by itself uninstall the git and re-install it again.

Step 5 : Use the sfdx-simple git repo, 

here is the link , we will get this repo in our system first, so clone it, follow below steps
Our first goal is to set up a developer project which we'll use to modify our application. It starts by cloning the repository. Use the command

             git clone https://github.com/forcedotcom/sfdx-simple.git


Then, open the directory.

             cd sfdx-simple


Step 6 : Login to SalesofrceDX

Run this command, it will install the NodeJS by itself as it requires NodeJs, and by this command we are login in to SalesforceDX org, and authorizing it.



So after this login window will open, where you need to put your salesforceDX credentials, and authorize, after that you can close the window



Step 7 : Now we will create a scratch org,


The scratch org is also created through the CLI, using a config file.
Run below command

              

              sfdx force:org:create -s -f config/project-scratch-def.json




So if you logged in the SalesforceDX org, you can see the data in Scratch org info. You are done as you've successfully created the scratch org.



Now, Push the repo metadata to scratch

      

       sfdx force:source:push



In the same way you can perform multiple actions using SalesforceDX CLI
to see more commands, enter

    

     $ sfdx force --help



Below are some commands you can use to create the metadata

To create apex class

        sfdx force:apex:class:create -n myclass


There are many things that we can do using SalesforceDX and SalesforceDX CLI, like continuos integration, source control and many more, soon will post about Salesofrce IDE 2, which can be used as of the important tool to leverage the functionality of SalesforceDX.

Here are some important links

SalesforceDX cli
SalesforceDX Developer Guide (Beta)
SalesforceDX CLI Configuration and tips
Sample Source in GitHub



thank you.