1

I was going through the documentation to automate data operation by loading the dataset that I am currently working on. Everything looks fine, but there is a use case where I am stuck.

There is a scenario where an Account record can have a parent account. In this case,

Insert Account:
    sf_object: Account
    table: Account
    fields:
        Id: sf_id
        Name: Name
        Order__c: Order__c
    lookups:
        Parent__c:
            table: Account

And this is in the SQL file:

CREATE TABLE "Account" (
    sf_id VARCHAR(255) NOT NULL,
    "Name" VARCHAR(255),
    "Order__c" VARCHAR(255),
    Parent__c VARCHAR(255),
    PRIMARY KEY (sf_id)
);
INSERT INTO "Account" VALUES(1,'ACC-1','1','');
INSERT INTO "Account" VALUES(2,'ACC-2','2',1);

But I am getting the below error:

Error: 'Account_sf_ids'

I believe this error is due to the fact that when the account records are being inserted, we don't have the Id of the 1st Account yet which I can associate with 2nd record.

Is it possible to make this work?

1 Answer 1

1

Disclosure: I am on the CumulusCI team and I wrote the code that does this type of data load.

Yes, you can load Account hierarchies and other hierarchies using CumulusCI. CumulusCI executes this as two operations: a load, with all of the ParentId fields null, followed by an update to populate ParentId fields mapped to the Ids of the newly-inserted records.

You instruct CumulusCI to do this by using an after: declaration on a relationship. There's an example in this section of the documentation:

Accounts:
    sf_object: Account
    fields:
        - Name
        - Description
        - RecordTypeId
    lookups:
        ParentId:
            table: Account
            after: Accounts

To modify your example mapping, you'd do

Insert Account:
    sf_object: Account
    table: Account
    fields:
        Id: sf_id
        Name: Name
        Order__c: Order__c
    lookups:
        Parent__c:
            table: Account
            after: Insert Account

The after: declaration takes the name of the step after which the lookup should be populated.

As a side note, you're using some older features in your mapping file that are no longer required. You're welcome, if you wish, to omit the table: declaration, the Id field, and the Name: Name mappings (in favor of a simple list), which gives you a more streamlined definition of your dataset:

Insert Account:
    sf_object: Account
    fields:
      - Name
      - Order__c
    lookups:
        Parent__c:
            table: Account
            after: Insert Account
3
  • I know about you David, Dan and Ryan told me about you. And I was hoping to get a reply from you only. :) If this works, I will mark your comment as the answer.
    – nica
    Commented Apr 20, 2022 at 4:07
  • lookup after: Insert Account seems to be broken with latest cumulusci version 3.84.3 . Any workaround to make this version work?
    – Naga
    Commented Feb 29 at 11:51
  • @Naga Revert to 3.84.1 until the CumulusCI team fixes it. See open issue in the GitHub repo.
    – David Reed
    Commented Feb 29 at 18:59

You must log in to answer this question.

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