• SteveTechArc
  • NEWBIE
  • 0 Points
  • Member since 2013


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I am trying to use Test.loadData to load parent and child records linked by the Master Detail relationship.

 

I have been referencing the follwoing:

 

SF DOC:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm

 

SF KNOWLEDGE ARTICLE

http://help.salesforce.com/apex/HTViewSolution?id=000167032&language=en_US

 

DISCUSSION BOARD

http://boards.developerforce.com/t5/Apex-Code-Development/Test-loadData-how-to-relationships/td-p/557477

 

However, none of these solve the problem.   Here is what I have done:

 

1)  Added an External ID field on both Parent and Child  "Load_Key__c"

2)  Created an Extra field on the Child, which holds the value of the External Id on the Parent. "PG_Load_Key__c"

 

Here is where things are not working.  

 

#1  

If I follow the examples, they instruct to do the Test.loadData with both Parent and Child.  Then, create a Map from the parent, setting the respective refernce.   This is where things fall down.  If I try the lodData on the child, with the Parent Reference empty, I get the error "Required fields are missing"

 

Therefore, I cannot get past the loadData on the child to add the references to the Parent.

 

#2

I tried just putting the Parent's External ID value into the Mater Detail field of the child and I get the error:  "Invalid ID value"

 

#3

I can load this data in the Data Loader using the External ID, (that does not help me with my test scripts).  I use a modified map file with the syntax: PG_Load_Key__c=Product_Group__r\:Load_Key__c

 

I have tried naming the field to see if it can leverage the same syntax, but it fails for these optons:

Product_Group__r\:Load_Key__c

Product_Group__r:Load_Key__c

Product_Group__r.Load_Key__c

PG_Load_key__c=Product_Group__r\:Load_Key__c

 

 

So, I am stuck.  I cannot load the child without the Parent Key.  I cannot modify the static resource file to put the key in at runtime.  I cannot find a way to have SF do the lookup on the External ID of the Parent.

 

How can anyone load Child (Master Detail) record with the Test.loadData()?

 

I have a complex object graph with about 8-10 objects with mutiple layered lookups and Master Details.

 

Has anyone accomplished this?

Steve

 

 

I am trying to use Test.loadData to load parent and child records linked by the Master Detail relationship.

 

I have been referencing the follwoing:

 

SF DOC:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm

 

SF KNOWLEDGE ARTICLE

http://help.salesforce.com/apex/HTViewSolution?id=000167032&language=en_US

 

DISCUSSION BOARD

http://boards.developerforce.com/t5/Apex-Code-Development/Test-loadData-how-to-relationships/td-p/557477

 

However, none of these solve the problem.   Here is what I have done:

 

1)  Added an External ID field on both Parent and Child  "Load_Key__c"

2)  Created an Extra field on the Child, which holds the value of the External Id on the Parent. "PG_Load_Key__c"

 

Here is where things are not working.  

 

#1  

If I follow the examples, they instruct to do the Test.loadData with both Parent and Child.  Then, create a Map from the parent, setting the respective refernce.   This is where things fall down.  If I try the lodData on the child, with the Parent Reference empty, I get the error "Required fields are missing"

 

Therefore, I cannot get past the loadData on the child to add the references to the Parent.

 

#2

I tried just putting the Parent's External ID value into the Mater Detail field of the child and I get the error:  "Invalid ID value"

 

#3

I can load this data in the Data Loader using the External ID, (that does not help me with my test scripts).  I use a modified map file with the syntax: PG_Load_Key__c=Product_Group__r\:Load_Key__c

 

I have tried naming the field to see if it can leverage the same syntax, but it fails for these optons:

Product_Group__r\:Load_Key__c

Product_Group__r:Load_Key__c

Product_Group__r.Load_Key__c

PG_Load_key__c=Product_Group__r\:Load_Key__c

 

 

So, I am stuck.  I cannot load the child without the Parent Key.  I cannot modify the static resource file to put the key in at runtime.  I cannot find a way to have SF do the lookup on the External ID of the Parent.

 

How can anyone load Child (Master Detail) record with the Test.loadData()?

 

I have a complex object graph with about 8-10 objects with mutiple layered lookups and Master Details.

 

Has anyone accomplished this?

Steve

 

 

In the User's Guide there is a sample http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm?CSHID=apex_methods_system_test.htm#TestLoadDataExampleSection

of how to use the Test.loadData method to load a csv file with Accounts.

 

I cannot see any documentation nor samples showing how to load records with references (lookup or master-detail) to parent records - e.g. if I want to load Contacts, which refer to Accounts.

 

Anyone who knows. I suppose I am not going to "invent" record IDs????