Saturday, May 30, 2020

Deep dive into Master Detail Relationships


In this post we will talk about things that are there to know related to M-D relationship.
I will try to cover things from basic to corner cases around M-D relationships.
Hopefully you will find something new in below post.
  • Owner field is not available on detail object rather it is set to owner of master record.
  • Sharing rules, manual sharing or queues cant be defined for detail object as these require owner field
  • OWD of detail object is controlled by Parent.
  • We have limit to create 40 relationship on an object and that limit can be achieved in any of below pattern. 
    • 39L 1 M
    • 38L 2 M 
    • 40L
(where L-> Lookup , M-> Master-Detail)
  • When we say an object has limit of 2 M-D its related to how many parents an object can have not how many details a parent can have.  For example Object A could be detail to Object B and Object C making it a junction object. I cant make it detail to Object D now.
  • When it comes to how many detail objects a master can have, as far as I know there is no limit, I have tested till 12 details under same master object. Do try it in your org...
  • Standard objects can't be on the detail side of a M-D relationship ie I cant even create Master detail relationship between two standard objects as that would mean one of them to be on detail side.
Let me know if you have any scenarios where you'd want to create master detail between two standard objects.
Currently there is an idea pending for enabling M-D between standard objects but not sure if it would be allowed as it would impact underlying schema,security,permissions and what not related to  objects.

Link to Idea : https://success.salesforce.com/ideaView?id=08730000000HBN2
  • You can have up to three custom detail levels ie for example  
    • Castle 
      •   Property  (Level 1)
        •   Supply (Level 2)
          •    Treasure (Level 3)
I cant create another relationship pointing to Treasure as it would void above limit.
  • We cant create master-detail relationship if the object already contains data. There are two ways to do it: 
    • We can either create a lookup field and then fill up all the records with a proper value then convert it into lookup.
    • Else we can go ahead and hard delete all the records , soft delete doesn't work as records stay in recycle bin for 15 days.
  • In a multi level relationship we cant create a roll-up field directly on grand child object ie in below scenario.
    • Castle - Parent 
      •   Property - Child 
        •   Supply - Grand child 
I cant create rollup field on Castle object to summarize data from Supply(Grand child) directly, rather I have to first create a roll on Property then create a roll up on Castle using that field on Property.
  • We cant delete an object which is master to any object.But we can delete an object which is on detail side of relationship. Here is a catch though if you at some point of time undelete the object relationship would be converted to lookup.
  • Now lets talk about deleting records in M-D relationship I have added few scenarios below: 
    • If I delete a detail record, master record stays intact and if i undelete detail record it will be linked back to master record.
    • If I delete master record all detail records will be deleted (ie including grand child records) and if I undelete the master record all the child records will also be undeleted and restored with old connections.
    • However if I delete a detail record first then delete a master record. Now if I undelete master record it will be restored back but without detail record and there is no way restore detail record now.
  • We can create cross object workflow in case of master detail relationship ie I can create a workflow on child object to update a field on parent object which is not allowed in case of lookup relationship.
  • You cant create master detail relation between custom object and User,Lead,Product,Pricebook etc you can although create lookup.
FYI : Even cascade delete option which we can get enabled from Salesforce doesn't work on object like User,Lead, Product, Pricebook.
  • A little about Junction objects (objects used to create M:M relationship) : 
    • If any of the master records are deleted junction object record will also be removed, if master record is undeleted junction object record is also restored back.
    • Deleting a junction object record doesn't delete master records.
    • First master detail created on Junction object is considered as primary relationship and if primary relationship is converted into lookup or deleted, other M-D relationship becomes primary.
    • Junction object inherits look and feel from primary relationship moreover junction object inherits value of owner from primary relationship.
    • OWD of junction object is most restrictive of both parents ie if Parent  1 is (Public Read only) and Parent2(Private) OWD of junction object will be private.
    • User must have at-least read access to both the parent records to be able to access junction object records.
    • Junction objects cant have any details objects.
Note : Above points are written assuming junction object is created with 2 M-D relationship.


Thanks for reading...

If you liked the post do support me by buying a pizza for me :D

No comments:

Post a Comment