0

I have a Salesforce project in which I will be automatically popualating custom SObjects from a Java app. This will be done by pulling data down from a database, parsing it (including a JSON payload), then pushing it to Salesforce to populate the objects.

I am having trouble figuring out how to ensure Master-Detail relationships get mapped correctly. I have one object (let's call it "report") which must be mapped to one or more instances of another object (let's call it "product")

To achieve this one to many relationship, I have a junction object. The junction object needs to be mapped to one report object record, and one or more product object records. Therefore, said junction object has a Master-Detail relationship to both the report and product objects.

What data does Salesforce need to make sure it gets mapped correctly? A record ID? Something else? It is important that the correct associations are made between a report and its associated products.

1

You are spot on the solution to your problem. A record Id of the Master object in child object's Master-Detail field would link it to the Master. In your case you would need the record Ids of Report and Product records in the junction object.

1
  • Marked as the answer :) Thank you! – Logan Snyder Feb 9 at 21:45
0

Tip: you have 2 options for relationships: Lookup, and Master detail. I think masterdetail might make sense for the junction>-report relationship, and for junction>-product, Lookup is probably fine.

To fill the junction fields, yes, you put the product/report salesforce record Id in those fields before insert.

Or...

If you have populated External Id fields on those objects, as well as in the JSON payload, you can use THOSE external identifiers instead, and you won’t even have to know the salesforce record IDs. Could be easier/less queries .

More info here How does upsert works with ExternalId https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_upsert.htm

See the bottom section of this page, to see how to insert records using external ids https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm

Also, remember that every insert() call can operate on arrays up to 200 records long (or 10k records if using the salesforce bulk api). So first, in a for loop, put all those junction objects into an array, then, call insert once (per 200). Boom. Less api calls.

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.