12 Mar 2016

One-To-Many Relationship

Two Types of One-To-Many Relationships
Master-Detail
  • The owner of master record automatically owns all associated detail records.
  • Security controls for the master record control the detail record.
  • A detail record must be linked to a master record in order to save the record (e.g. you must link an opportunity to account to save the opportunity).
  • Only one level deep  a detail object cannot also be a master object.  Please vote to remove this limitation:
A detail record can have two different master records (two master-detail relationships must be created).This feature was released in Summer 08 to give greater flexibility when creating many to many relationships as described above.  Prior to then, only one master-detail record could be present per object, meaning that record deletions for object Job Posting to Applicant Link€ could only be triggered by a Job Posting deletion or an applicant deletion; not either.Example:
I have created two Objects in order to show how to create master-detail relationship.
Object2 Named: Child Object

Go to Child Object and Click on New button





    

childrelatedlist
Any questions please do write back. :)
Master-detail relationship also know as Parent-child relationship.
  1. Child row not automatically deleted when a parent row is deleted
  2. No inherited sharing.
  3. 25 lookup relation relationships allowed per object.
  4. Lookup field on child not necessarily required. 
  5. Add Lookup Relationship
  • Master controls the behaviour of detail Object, if the master is deleted,all its child records will be deleted.[One of the difference between lookup and master-detail relationship]
    Now we would be creating the M-D relationship
    Object1 Named: Master Object
    We have two objects ready. Time to create a custom field with data type [Master-Detail Relationship].
    Now select data-type as 'Master-Detail Relationship'
    Next Step to mention the master object name , In this case I have used as 'MasterObject'
    Mention the Field label name
    Click Next in Step 4 and 5 , as its read only page and you will not able to edit anything
    Now final step 6 , you need to choose whether you want to show the related list on the master record or not
    Now Save.
    Our Master-Detail relationship is ready , create a new record on Child object and you will find a mandatory lookup, that's your Master Object reference.
    Child record
    Hope you have enjoyed! remember don't forget to do it practical and share your demo screen with me.
Lookup Relationship
  • This type of relationship links two objects together, but has no effect on deletion or security. Unlike master-detail fields, lookup fields are not automatically required. When you define a lookup relationship, data from one object can appear as a custom related list on page layouts for the other object. See the Salesforce online help for details.