5

Playing with the export/import tree commands in the Salesforce DX beta. I've had luck exporting/importing parent/child records as demonstrated in the docs, but is it possible to use that command to bring in more than 2 objects at once? Something like Accounts, Contacts, Opportunities and Contact Roles?

From what I can tell you're limited to what you can pull with one query, but I wanted to see if anyone can validate that.

2 Answers 2

7

This command follows the basic rules of SOQL in how it is implemented. Of course you must adhere to the limitations of relationship queries in SOQL as well. In this instance the important limitation is the that of only being able to query one level deep from Parent to Child. So you could get as far as

SELECT Id, Name, 
  (SELECT Id, Name FROM Opportunities), 
  (SELECT Id, Name FROM Contacts) 
FROM Account

But querying OpportunityContact in one go would not be possible, I'm afraid. This command makes a single SOQL call to the org.

The good news is the DX team is writing the CLI to be pluggable, and they are signaling intention to open it up for community to contribute plugins, as well as write their own. (There was a session talking about this at TrailheaDX.) So at some point in the future you might be able to write (or get someone to write) a plugin that actually performs several queries and constructs a plan to pass to the tree:import command.

Side note: I'm pretty sure that tree:import would support the import of the structure you describe as this is simply a wrapper around the REST SObject Tree API. I've not tested it, but it appears to fit the criteria described in the docs.

0
9

So this turned out to be pretty simple. You can create a plan.json with more than 2 steps. You need to make sure your total record count stays below 200, but as long as you set the saveRefs in the plan to true for each step you can manually change all your foreign keys to internal reference. This works particularly well if you export your records the right way. Say you have tables A->B->C

If you export A subselect B, and then B subselect C. So long as your B records are selected in the same order in both queries you can just update the Plan you got from A/B with the C block from the B/C plan.

2
  • Is there a less manual way to do it?
    – Edmondo
    Apr 9, 2019 at 10:10
  • can you send some more info ? Nov 20, 2019 at 12:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .