Import Child Objects

  • 1
  • Idea
  • Updated 3 years ago
  • Implemented
Imports Related to Parent Objects - I am testing a page which creates child records and parent records in one Skuid page. It would be cool if I could import child records in this process. Either that, or suggesting to avoid it in this scenario.

Basically, the "Create Child Objects and Parent Objects" tutorial + "Use Import Wizard from Global Action Button" are not currently compatible.

I conclude my effort to put square pegs into round holes.
Photo of Jacob Flatter

Jacob Flatter

  • 1,512 Points 1k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,004 Points 20k badge 2x thumb
Official Response
This is not doable in "one step", but it is possible to import child records related to a parent using the Skuid Import Wizard.

The basic trick to know is that you can pass in additional URL Parameters to the Skuid Import Wizard that will be used to set values on all records imported via the Wizard, via the syntax:

/apex/skuid__Import?obj=OBJECT_NAME[&FIELD_API_NAME=VALUE]

e.g.

/apex/skuid__Import?obj=Contact&AccountId=00100000000CBAhAAB
/apex/skuid__Import?obj=Case&Status=New&Priority=Low
/apex/skuid__Import?obj=My_Object__c&My_Field__c=My+Value&Priority=Low

For example, say that your parent object is Account, and your child object is Contact. So say you have a multi-step wizard. In Step 1, you create the parent object (an Account). In Step 2, after you've saved the Account, you take the user to a table of related Contacts. You have a Global Action on this Table that allows users to Import Contacts. The problem is that normally, with any Import Wizard, in order to link these new Contacts to a related record (here, to a parent Account, via the "AccountId" field) your users would have to have a column in their CSV file with header "AccountId" that contains the Id of the Account. But this would be really tedious for users --- why should they have to copy the Id of the Account out of Salesforce, put it into their CSV, then Import? What would be great is to be able to just have the Id of the Account you are looking at be passed in to the Skuid Import Wizard and applied to all imported Contacts.

Good news is, you can do this!

All you have to do is adapt the URL for your Global Action to pass in the Id of the Account. How do you get this? Use Skuid Merge syntax to grab the Id of the first Account in your Account Model. So let's say that your Account Model is called "MainAccount". Here's what your URL would be:



/apex/skuid__Import?obj=Contact&AccountId={{$Model.MainAccount.data.0.Id}}



This will make it so that all Contacts imported via the wizard would be associated to this particular Account, by populating the AccountId field with the Id of the first row in your MainAccount model.

To make it so that the Import Wizard will prompt you to return back to a particular page, e.g. your Account detail page, all you have to do is pass in a "retURL" parameter that defines the URL the Wizard should return you to, like this:



/apex/skuid__Import?obj=Contact&AccountId={{$Model.MainAccount.data.0.Id}}&retURL=%2F{{$Model.MainAccount.data.0.Id}}



Here's what this looks like: