blog

Migrating Existing Projects to Salesforce DX

Are you ready to move to Salesforce DX, but your source code is currently in a Developer Edition (DE) or Sandbox org? In this blog post, I describe the easy steps to convert existing source code to a Salesforce DX project.

I recently converted the latest version of the DreamHouse sample application to a Salesforce DX project, and I thought it would be helpful to document the process so you can use the same steps to convert your own projects to Salesforce DX. The end result for the the DreamHouse app is available in this repository, but the steps below are applicable to any project.

Step 1: Convert your project to Salesforce DX

  1. Create an unmanaged package in your existing org, and include all the assets you want to move to your Salesforce DX project. You don’t need to upload the package, and you don’t have to worry about the 75% code coverage for this purpose.
  2. If you haven’t already done so, authenticate with your hub org. Type the following command, then login with your hub org credentials and accept to provide access to Salesforce DX:
    1 sfdx force:auth:web:login -d -a myhuborg
  3. Create a new Salesforce DX project:
    1 sfdx force:project:create -n myproject
    2 cd myproject
  4. Authenticate with your developer edition org. Type the following command, then authenticate with your developer edition org credentials and accept to provide access to Salesforce DX:
    1 sfdx force:auth:web:login -a mydevorg
  5. Export the unmanaged package metadata in a temporary directory. Type the following commands in the root folder of your Salesforce DX project:
    1 mkdir temp
    2 sfdx force:mdapi:retrieve -s -r ./temp -u mydevorg -p mypackage

    “mypackage” is the name of the unmanaged package you created in step 1. Afer executing this command, a file named unpackaged.zip is created in the temp directory.

  6. Unzip unpackaged.zip using a zip file management utility or from the command line. For example, on a Mac, double-click unpackaged.zip in Finder or type the following command on the command line:
    1 unzip ./temp/unpackaged.zip -d ./temp/
  7. Convert the source code to the Salesforce DX project structure:
    1 sfdx force:mdapi:convert -r ./temp

    You can delete the temp directory at this point.

  8. Create a scratch org:
    1 sfdx force:org:create -s -f config/project-scratch-def.json -a  myscratchorg

    If you get an expired access/refresh token message, authenticate with your hub org again (step 2 above).

  9. Push the code to your scratch org:
    1 sfdx force:source:push
  10. Open the scratch org:
    1 sfdx force:org:open
  11. Create a permission set to provide access to your project’s assets:
    • In Setup, type permission in the quick find box, click the Permission Sets link, and click New
    • Provide a name for your permission set and click Save
    • Add the required permissions
    • Click Manage Assignments and assign the permission set to the default user (User, User)

    For example, here are the permissions I added for the DreamHouse app:

    • Assigned Apps: I added the DreamHouse app
    • Object Settings: I added all available permissions (Tab settings, Object Permissions, and Field permissions) for all the custom objects used in DreamHouse: Broker__c, Property__c, Favorite__c and Bot_Command__c.
    • Apex Class Access: I added all the classes
    • Visualforce Page Access: I added all the Visualforce pages
    • In the Find Settings box, I typed the name of all the tabs used in DreamHouse (HeatMap, HeatMap demo, Einstein Vision, and Command Center), and I enabled access (checked Visible).
  12. Pull the permission set
    1 sfdx force:source:pull

Step 2: Transfer sample data (Optional)

The Salesforce DX CLI also makes it easy to export sample data from your developer org and import it in your scratch orgs. It even preserves master-details relationships between records. As an example, here is how I did it for the DreamHouse app:

To export the data from my DE org, I ran the following command from the root folder of my Salesforce DX project:

01 sfdx force:data:tree:export -q "\
02     SELECT Id, \
03            Name, \
04            Title__c, \
05            Phone__c, \
06            Mobile_Phone__c, \
07            Email__cPicture__c, \
08            (SELECT Id, \
09                    Name, \
10                    Address__c, \
11                    City__c, \
12                    State__c, \
13                    Zip__c, \
14                    Price__c, \
15                    Title__c, \
16                    Beds__c, \
17                    Baths__c, \
18                    Location__Longitude__s, \
19                    Location__Latitude__s, \
20                    Picture__c, \
21                    Thumbnail__c, \
22                    Description__c \
23             FROM Properties__r) \
24     FROM Broker__c" \
25     -u mydevorg --outputdir ./data --plan

After executing this command, the sample data files (Broker__cs.json, Property__cs.json, and Broker__c-Property__c-plan.json) are available in the data subfolder of my project which means that they will be part of the project when I put it under version control (step 3 below).

To import the data in my scratch org, I run the following command:

1 sfdx force:data:tree:import -u myscratchorg \
2     --plan ./data/Broker__c-Property__c-plan.json

Step 3: Put your project under version control

We are done converting the project and transferring data. It’s time to put the project under version control. For example, using Github:

1 git init
2 git add . -A
3 git commit -m 'first commit'
4 git remote add origin https://github.com/yourname/your-repo.git
5 git push origin master

That’s it. It’s now easier than ever for other developers to work with you on the project. Using the migrated DreamHouse project as an example, all they have to do is:

  1. Clone the repository. For example:
    1 git clone https://github.com/dreamhouseapp/dreamhouse-sfdx
    2 cd dreamhouse-sfdx
  2. Create their own scratch org:
    1 sfdx force:org:create -s -f config/project-scratch-def.json -a myscratchorg
  3. Push the app to their scratch org:
    1 sfdx force:source:push
  4. Assign the permission set to the default user. For example:
    1 sfdx force:user:permset:assign -n dreamhouse
  5. Import data in the scratch org. For example:
    1 sfdx force:data:tree:import -u myscratchorg \
    2     --plan ./data/Broker__c-Property__c-plan.json
  6. Open the scratch org:
    1 sfdx force:org:open

Summary

Salesforce DX enables modern development workflows on the Salesforce platform. It makes team development, version control, and continuous integration easier than ever. Migrate your existing projects to Salesforce DX today using the easy steps described in this post and watch the pull requests come in!

Related posts

5 Replies to “Migrating Existing Projects to Salesforce DX
  1. 拉皮原理、拉皮種類、前額拉皮、抬眉手術、傳統前額拉皮、內視鏡前額拉皮、直接抬前額拉皮、改良式髮際線拉皮、五爪拉皮術等一些相關議題、似是而非或有爭議的事項的披露與討論。

    https://skinac.com/tag/膠原增生

  2. Restylane乃一系列用於美顏的長效透明質酸產品。 Restylane療程能有效撫平皺紋、美化臉型輪廓及唇部,並可改善膚質及肌膚的彈性。Restylane透明質酸作用原理 Restylane透明質酸均以非動物來源的透明質酸作為原料,獨有的NASHA™專利技術研製而成。微量Restylane透明質酸凝膠到皮膚中,可以讓您的面部肌膚恢復豐盈飽滿。 Restylane透明質酸中的透明質酸與人體內的天然透明質酸十分相似,使用前無需進行皮膚測試,引起過敏反應的機率亦極低。

    http://cosmedicbook.com/treatments/info/HIFU-無創超聲波4D拉皮

  3. 通過水光療程抑制黑色素細胞生長的成分注射到真皮層,減少黑色素形成,淡化黑斑色素沉澱,從而達到美白祛斑的效果 療程特色 :可配搭多元化產品來量身訂做不同療​​程計算機化規格,操作方便,容易控制可調節進針深度,精準注射於目標的肌膚層 每針的注射劑量相等,達到均勻注射 一次平均5點注射,可縮短療程時間 採用31號細針頭,幾乎看不到入針點 降低疼痛、瘀血、腫脹及不適感 使用靈活度高,可複合式搭配針劑,量身訂製療程

    http://cosmedicbook.com/treatments/info/-激光陰道收緊療程

Leave a Reply