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 is created in the temp directory.

  6. Unzip using a zip file management utility or from the command line. For example, on a Mac, double-click in Finder or type the following command on the command line:
    1 unzip ./temp/ -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
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
    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


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

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

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

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

  4. I truly wanted to develop a quick remark in order to thank you for the amazing strategies you are sharing at this website. My extended internet investigation has now been compensated with really good details to go over with my classmates and friends. I would declare that many of us readers are undeniably blessed to live in a notable community with so many brilliant professionals with interesting techniques. I feel pretty fortunate to have encountered your web site and look forward to many more excellent times reading here. Thank you once again for all the details.

  5. I am writing to let you be aware of what a incredible discovery my daughter experienced reading your webblog. She even learned too many details, which include how it is like to have a marvelous giving heart to make many others without problems completely grasp chosen impossible topics. You really did more than our own desires. I appreciate you for showing these warm and helpful, healthy, edifying and in addition cool thoughts on the topic to Lizeth.

  6. I truly wanted to compose a word so as to thank you for all of the wonderful techniques you are sharing here. My rather long internet investigation has at the end of the day been recognized with brilliant know-how to share with my good friends. I would express that many of us website visitors actually are definitely lucky to live in a useful community with very many perfect people with useful strategies. I feel very grateful to have discovered the website page and look forward to some more fabulous times reading here. Thanks again for all the details.

  7. I precisely needed to appreciate you all over again. I do not know what I would have gone through in the absence of the type of hints shared by you directly on this concern. Previously it was a very alarming concern in my view, nevertheless understanding this expert technique you resolved it forced me to jump with contentment. I am just happier for this support and thus wish you are aware of a powerful job that you are putting in teaching the others through the use of your webblog. Most probably you’ve never come across any of us.

  8. I’m just writing to let you be aware of of the magnificent discovery my cousin’s daughter enjoyed using the blog. She even learned some pieces, most notably what it’s like to possess a wonderful teaching nature to make other folks with no trouble learn specific specialized matters. You truly surpassed our own expected results. I appreciate you for presenting those precious, safe, educational and even cool tips about the topic to Ethel.

  9. I must express appreciation to the writer just for bailing me out of this condition. Just after looking out through the world wide web and getting tricks that were not helpful, I thought my entire life was done. Living without the answers to the problems you’ve resolved all through the post is a crucial case, and ones that might have in a negative way damaged my entire career if I had not noticed your web page. Your own personal understanding and kindness in taking care of almost everything was very helpful. I am not sure what I would have done if I had not encountered such a point like this. I can at this point relish my future. Thanks very much for the skilled and sensible guide. I won’t hesitate to endorse your web sites to any individual who needs to have direction on this issue.

  10. I not to mention my pals have been reviewing the excellent tips and hints from your web blog and then all of a sudden came up with a horrible suspicion I never thanked the web site owner for those tips. Most of the guys are already certainly passionate to read through all of them and now have truly been enjoying these things. Appreciate your being indeed accommodating and also for going for this form of wonderful issues most people are really desperate to learn about. Our own sincere apologies for not expressing gratitude to earlier.

  11. I intended to compose you one little bit of word to help say thanks a lot over again regarding the breathtaking information you’ve provided in this case. This has been certainly incredibly generous of people like you to give freely what exactly most of us would’ve supplied for an e book in making some profit on their own, especially considering that you might well have done it in the event you decided. The principles likewise worked like the great way to recognize that someone else have a similar fervor just like my personal own to grasp more and more in regard to this problem. I’m sure there are numerous more pleasurable times ahead for people who find out your blog.

  12. My wife and i were absolutely happy when Emmanuel could conclude his reports through the precious recommendations he had in your web pages. It is now and again perplexing to just be making a gift of hints that many other folks may have been trying to sell. We really acknowledge we have the website owner to appreciate because of that. The specific illustrations you made, the straightforward blog menu, the friendships you aid to promote – it’s got all overwhelming, and it is assisting our son in addition to us reckon that the subject is awesome, which is highly essential. Thanks for the whole thing!

  13. Thank you so much for providing individuals with an exceptionally terrific possiblity to discover important secrets from this website. It’s usually so brilliant and as well , jam-packed with fun for me personally and my office fellow workers to search your site the equivalent of three times in 7 days to read the new items you have. And definitely, we are at all times fascinated with all the awesome tactics you give. Certain 1 points on this page are truly the most efficient I have ever had.

  14. Read our in-depth iPhone XS Max review
    Read our hands-on iPhone XR review
    Read our hands-on Apple Watch 4 review
    iPhone XS price and release date
    iPhone XS

  15. Los Blancos, with captain Sergio Ramos suspended after deliberately collecting a yellow card in the first leg, had been looking to build on a slender 2-1 lead from that game in Amsterdam and stay on course for a potential fourth straight European triumph.

    However, after Raphael Varane’s header rattled the crossbar, Ajax raced into an early lead through Hakim Ziyech before Dusan Tadic set up David Neres for a second in the 18th minute.
    Real Madrid were forced into two changes when Lucas Vazquez and Vinicius Junior went off injured, with substitute Gareth Bale hitting the post just before half-time.

    Ajax looked to have put the tie to bed when Tadic swept in a brilliant third goal just after the hour – which was eventually given following an extensive Video Assistant Referee review to check if the ball had gone out of play in the build-up.

  16. Trump was surrounded at Friday’s event by officials from Customs and Border Protection as well as surviving family members of those who have loved ones killed by undocumented immigrants. Attorney General William Barr was also at the President’s veto event.
    While some lawmakers including some Republicans — have argued against the President’s use of national emergency powers in this instance, the Justice Department set forth a robust defense of the President’s authority to do so in a letter to Senate Majority Leader Mitch McConnell earlier this month, according to a copy obtained by CNN on Friday.
    “The President acted well within his discretion in declaring a national emergency concerning the southern border,” wrote Assistant Attorney General Stephen Boyd, setting out the legal basis for the proclamation under the National Emergencies Act and additional statutory authorities, which largely tracks an internal memo issued by the Office of Legal Counsel at the Justice Department.

Leave a Reply