2

For Master-Detail relationship fields, the DescribeFieldResult has a method called getRelationshipOrder(), which, according to the docs:

Returns 1 if the field is a child, 0 otherwise.

At first I assumed that this meant that this would always return 1 for any Master-Detail field, but that's not the case.

In testing, it appears that the "order" refers to the order of field creation.

For instance, I created two Master-Detail fields on an object called Test__c, in this order:

  1. Account__c: Master/Detail on Account
  2. Contact__c: Master/Detail on Contact

Inspecting the DescribeFieldResult getRelationshipOrder() for these two fields, Account__c had 1, Contact__c had 0.

Next, I deleted Account__c. This caused Contact__c to have Relationship Order of 1.

I then undeleted Account__c, and made it Master/Detail again. Contact__c retained its Relationship Order of 1, and Account__c took on Relationship Order 0.

So my question is, does getRelationshipOrder() really just help you determine which Master/Detail field was created first, and if so, what does this matter? Do Master/Detail fields with Relationship Order 1 behave differently than Master/Detail fields with Relationship Order 0 ?

1 Answer 1

3

@zachelrath, the below info from Salesforce Help & Training may answer your question.

The first master-detail relationship you create on your junction object becomes the primary relationship. This affects the following for the junction object records:

  • Look and feel: The junction object's detail and edit pages use the color and any associated icon of the primary master object.
  • Record ownership: The junction object records inherit the value of the Owner field from their associated primary master record. Because objects on the detail side of a relationship do not have a visible Owner field, this is only relevant if you later delete both master-detail relationships on your junction object.
  • Division: If your organization uses divisions to segment data, the junction object records inherit their division from their associated primary master record. Similar to the record ownership, this is only relevant if you later delete both master-detail relationships.

The second master-detail relationship you create on your junction object becomes the secondary relationship. If you delete the primary master-detail relationship or convert it to a lookup relationship, the secondary master object becomes primary.

P.S. Thank you for doing the research on what 1 and 0 mean as returned by getRelationshipOrder().

You must log in to answer this question.

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