Pages

Friday, September 12, 2014

Using the Force.com CLI

Force.com CLI tool allows you to interact directly with Force.com from your command-line.
Functionality includes exporting metadata and packages created in SFDC to a local directory, browsing data objects, executing SOQL queries, executing APEX code,managing custom objects etc.


Download Force.CLI from https://force-cli.heroku.com/

Download Force.com CLI executable file and store it in some folder. Suppose my folder name is "CLI Demo" present in E: drive.


Now Open Command prompt  and go to CLI Demo Folder and use below commands:
E:\CLI Demo>force version


If you are getting version information then it means CLI is configured correctly. Otherwise if you getting some error, then set system variable by navigating computer->my properties-Advanced system settings->Environment variables. Provide CLI Demo folder location in path variable.


Once Force.com CLI is configured properly, then we can use it to export package created in SFDC to local directory. Follow below steps:
  1. Create a package: Go to SetUp-> Create->Packages. Create a new package and include all elements which you want to export from SFDC.
  2.          Now you can go to command prompt and enter following commands:
             First we need to login to SFDC instance in order to fetch package

        For Production and developer sandbox use
        force login -i=login.salesforce.com  -u=USERNAME  -p=PASSWORD+SECURITYTOKEN
                           or
        force login -u=USERNAME  -p=PASSWORD+SECURITYTOKEN

       For Sandbox
        force login -i=test.salesforce.com -u=USERNAME  -p=PASSWORD+SECURITYTOKEN

            To fetch package details:

      force fetch package PACKAGENAME --unpack

      In our case package name is “ForceCLIDemoPackage” so enter

      fetch package ForceCLIDemoPackage --unpack


Now metadata folder is created in CLI Demo folder which contain all components information present in package. If you open it, you will see package.xml containing all components list.


Note: If you deploy components in SFDC org using Workbench, then Force.com CLI will help you create package.xml file easily. You don’t have to manually create package.xml file. Just create package in your source org and Fetch it with Force.com CLI and the zip all contents (package.xml and all folders present in ForceCLIDemoPackage). After this deploy the zip file using workbench to target org.

Available commands:
   login     Log in to force.com
   logout    Log out from force.com
   logins    List force.com logins used
   active    Show or set the active force.com account
   whoami    Show information about the active account
   sobject   Manage standard & custom objects
   field     Manage sobject fields
   record    Create, modify, or view records
   bulk      Load csv file use Bulk API
   fetch     Export specified artifact(s) to a local directory
   export    Export metadata to a local directory
   fetch     Export specified artifact(s) to a local directory
   import    Import metadata from a local directory
   query     Execute a SOQL statement
   apex      Execute anonymous Apex code
   oauth     Manage ConnectedApp credentials
   version   Display current version
   update    Update to the latest version
   push      Deploy single artifact from a local directory
   password  See password status or reset password
   help      Show this help

Run 'force help [command]' for details.





6 comments:

  1. Great article. Very helpful thanks

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Nice information thank you,if you want more information please visit our link salesforce online training
    salesforce login

    ReplyDelete
  4. Secondary Memory: It would serve well to take a moment to learn about another memory type - the Secondary Memory IPU. At times it is necessary to retain the program for future use. The Primary Memory would not serve this purpose and this comes in the Secondary Memory also called the "Backing Storage".

    ReplyDelete
  5. Good information though, I want essay services online in canada. Does anyone suggest me ?

    ReplyDelete