I'm trying to find the definition for saveRef and resolveRef. I'm seeing these attributes in my Json plan files. What do they mean?

  • 1
    Best you explain more about where your "Json plan files" come from. If it's a 3rd party system rather than Salesforce, best to ask on a forum that is about that 3rd party system. – Keith C Mar 19 '18 at 18:18
  • 2
    @KeithC They're in relationship to SFDX data imports (force:data:tree:import). – sfdcfox Mar 19 '18 at 18:20
  • @sfdcfox Thanks. Will be interested in the answer. – Keith C Mar 19 '18 at 18:21

The goal of the data commands are to import and export data. The problem with importing new records is that you don't know what the ID values are beforehand. So, if you're importing Accounts and Contacts, you need a way to associate the Contact to each Account, without an ID. You need a Plan. A Plan is a metadata file that explains how each JSON file is related to each other, and the order in which files should be imported. Each record in a JSON file needs to have a "referenceId", a unique identifier within the entire Plan so you can reference the appropriate parent records later.

So, for each parent record, you need to save a reference to the record; after inserting, there will be a result object that says something like "accountRef123" equals "0015000000abcde". Normally, these results are discarded (saveRefs: false), but if you need those ID values later, you'll want to save them (saveRefs: true). Then, in the subsequent files, whenever a lookup field uses a value starting with an @ (e.g. "@accountRef123"), it can resolve the reference you previously saved (resolveRefs: true). Obviously, both saving and resolving references involve extra disk space and CPU time, so if you don't need them, you don't need to save/resolve them.

If you use force:data:tree:export with the -p option, a Plan is created for you, and these flags will be set for you automatically. If you're constructing your data by hand, simply remember that if you need a referenceId to be used in a later JSON file, saveRefs must be true, and if you need to use @ references, then resolveRefs must be true.

  • Could you pelase clarify how would you make usage of the saveRefs result? The saveRefs results are written ona . disk, and when you do the import of a second json they will be resolved from the same folder? – Edmondo1984 Apr 9 '19 at 10:24
  • @Edmondo1984 Like I said, you use the plan file to import multiple JSON files in a single command, and the saveRefs saves a "ref to salesforce Id" value. I haven't experimented with separate commands and how that works with saveRefs/resolveRefs, but normally you'd use these values within the same plan file (a plan is a list of JSON files to import in order, linked together by refs). – sfdcfox Apr 9 '19 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.