Lookup or Master-Detail Relationship

[youtube id=fUD4MzgA0gk]

Note:  Roll-up summary fields per object has been increased to 25 (previously 10) as of the Winter 16 release.

[box type=”note” style=”rounded” border=”full”]Many standard object relationships exhibit behaviors of both a master-detail and lookup relationship.[/box]

For instance, opportunity to account is a lookup field.

However, you can establish roll-up summary fields on account to summarize opportunity data.  And when an account is deleted, all related opportunities are deleted as well.

You don’t need to know the nuts and bolts of every standard relationship, but it is important to know that not all standard relationships are equal.

40 thoughts on “Lookup or Master-Detail Relationship”

  1. Hi John,

    I have a question about the following statement, particularly the segment after ‘however’:

    Source: https://help.salesforce.com/articleView?id=overview_of_custom_object_relationships.htm&language=en_US&type=0

    Deleting a detail record moves it to the Recycle Bin and leaves the master record intact; deleting a master record also deletes related detail and subdetail records. Undeleting a detail record restores it, and undeleting a master record also undeletes related detail and subdetail records. However, if you delete a detail record and later, separately, delete its master record, you cannot undelete the detail record, as it no longer has a master record to relate to.

    Does this mean that master-detail relationships are deleted when a parent record is deleted and the relationship cannot be restored even after record restoration? If yes, is it also the case with lookup relationship?

    Thanks.

    1. OK this is a fun one.

      This means that the relationship between a DELETED detail record is broken when the master record is deleted.

      E.g.

      Account (Master)
      Location (Detail)

      Create account 1
      create location 1 –> account 1

      Delete account 1, delets. location 1. restore account 1, restores location 1.

      Delete location 1, restore location 1. no problem.

      Delete location 1, THEN delete account 1. Restore account 1 will not restore location 1 as this linkage is severed.

      That’s how I read it… might be fun to test out

  2. is below statement correct?
    “When you delete a child record on a roll-up Summary field, Salesforce doesn’t recalculate the value of the field. Select the Force a mass recalculation on this field option on the edit page of the roll-up summary field to manually recalculate the value.”
    I created roll up summary field in Bugs object for number of cases linked to it. When I deleted the case, the roll up summary on bug was automatically recalculated. Hence above stament doesn’t seem right. It’s mentioned @ https://help.salesforce.com/HTViewHelpDoc?id=fields_about_roll_up_summary_fields.htm&language=en_US

  3. Hi John

    I saw the below ADM sample question. As per site the answers is “Crossobject formula
    field”. I thought it is “Look-up Field”. Any idea ?

    Universal Containers uses a custom field on the
    account object to capture the account credit
    status. The sales team wants to display the
    account credit status on opportunities Which
    feature should a system administrator use to
    meet the reqquirements?
    o Look-up Field
    o Roll-up summary field
    o Workflow field update
    o Cross-object formula field

    1. I think i would have also gone for look up field had I not tried it myself. The limitation of look up field seems to be it copies name field from parent (so copies account name on opportunity when you create look up field in opportunity). It sounds a serious limitation that you can not map fields of source and target(otherwise we could have mappend Credit Rating on Account with Credit Rating on opportunity).

      To me Cross Object Formula seems to be correct answer in that case but me being newbie could be wrong.

      Regds
      Nikhil

  4. Hi John

    1. I created a custom object called Applicant and added some records.
    2. Created a Lookup relationship to Cases.
    3. Updated the Applicant records to update the Cases.
    4. Then went back and updated the relationship type with Cases to Master Detail.

    Why is it not allowing me to associate more than one case for a new applicant ?

    Any idea what else needs to be enabled or If i’m doing something wrong ?

    Thanks

  5. Just another Tip:

    You cannot create a new Master-Detail relationship on an existing custom object if records already exist. You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail

  6. Hi John,
    I’ve got this adm201 dump from another site:
    “True or False: The detail object of a master-detail relationship cannot also be a master object of another relationship.”
    I answered False but according to the site, the correct answer is True. I don’t understand. For instance, I have three objects in my dev org – Candidate, Job Application, and Review.
    Job Application is a detail object of Candidate, while Review is a detail object of Job Application. Thus, Job Application is detail object of a master-detail relationship (to Candidate), while at the same time a master object to another relationship (Review). Am I correct? Or I’m not getting the question right?

  7. Thank you for responding, John. I got doubt as multiple places in sf documentation it is mentioned:

    Notes on Cross-Object Field Updates
    For all custom objects and some standard objects, you can create workflow and approval actions where a change to a detail record updates a field on the related master record. Cross-object field updates work for custom-to-custom master-detail relationships, custom-to-standard master-detail relationships, and a few standard-to-standard master-detail relationships.

    Link:
    https://help.salesforce.com/apex/HTViewHelpDoc?id=workflow_field_update_considerations.htm&language=en_US

  8. hi, john,
    i want to ask u that can we convert relation ships later after creating them …
    as we realize later that the one look up i created …that need roll up summary…so can i convert it to master any how …
    or the other way if i created lookup and thought its useless to make master detail at that point , can i convert to look up?
    is it possible?
    And i also want to know how many master and how many look up relations are possible in an object or field?

    1. I believe you can convert between the two. To convert lookup to m/d you would need to make sure all values were populated. Not sure about m/d to lookup – if possible you would need to ensure there were no rollup fields.

  9. John, I’m not clear on why you needed to create a Cross-Object Formula to add Seats to the Course Offering page. You were able to add “Name of Course” by selecting it from a list. Why can’t you just add Seats in the same way?

    1. The number of seats would be derived from the classroom (e.g. this room holds 30 people). Therefore when a course is offered in this room, it should allow for 30 people. In order to copy that data from one object to another, you’d need a formula field.

      On the classroom you can see customize the related list of course offerings to include any fields you’d like (as this is a function of the related list), however, all the course offering will display is a link to the classroom record.

      The same would be true for accounts – you can choose which fields of the related opportunities you want to display. However, on the opportunity record itself, you would need to use a formula to display fields from the account.

  10. Note: The header in the presentation says “Fields.” Shouldn’t this say “Objects?”

    Question: Are Related Lists Detail objects of Master Objects? For example Account (master) and Contacts (detail)

  11. I thought the Account and Opportunity relationship was a master-detail, but opportunities are standard objects. is this an exception?

Leave a Reply