Lookup or Master-Detail Relationship

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

Many standard object relationships exhibit behaviors of both a master-detail and lookup relationship.

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.

49 Responses to “Lookup or Master-Detail Relationship”

  1. BQ2016 November 9, 2017 at 5:24 pm #

    “However, you can establish roll-up summary fields on account to summarize opportunity data.”

    I was confused by the statement above and it seems conflict with the video said “Roll-Up Summary field cannnot be established in the Lookup relationship”

    • JohnCoppedge November 13, 2017 at 8:17 pm #

      There are specific lookup fields (e.g. opportunity to account) that allow master-detail relationships (if you were to re-create them with a custom lookup relationship field, it would not)

  2. Gautam Kasukhela March 19, 2017 at 3:25 pm #

    Hello John,
             I have a confusion with reference to the following question:-

    “An sObject named Application _c has a lookup relationship to another sObject named Position_c.
    Both Application _c and Position c have a picklist field named Status_c.
    When the Status c field on Position __c is updated, the Status_c field on Application _c needs to be populated
    automatically with the same value, How can a developer accomplish this?

    A . By changing Application c.Status c Into a roll-up summary field.
    B. By changing Application c.Status c Into a formula field.
    C. By using an Apex trigger with a DML operation.
    D. By configuring a cross-object field update with a workflow. ”

    I choose option ‘C’ as the answer. My reasoning:
    Having a lookup relation with another object is like a Child to Parent relation. In this case Position_c is the Parent and Application _c is the child, just like Account and Contact. Hence to update a field in the child record when a parent record is updated, we should use Triggers. (as process builder is not amongst the options provided). 

    Is my understanding incorrect? 

    • JohnCoppedge March 20, 2017 at 6:23 pm #

      That would be my read as well- workflow would work with a master/detail but this is a lookup

  3. b.v.anuraag March 3, 2017 at 7:01 pm #

    Hi john , can you please type the content of video from 2:14 to 2:40 time frame i couldn’t get it.
    Thank you 🙂

  4. Mandy November 19, 2016 at 3:56 am #

    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.

    • JohnCoppedge December 17, 2016 at 1:24 am #

      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

      • Mandy December 17, 2016 at 6:55 am #

        Hi John, thanks for the detailed explanation! May test out later to see 🙂 Thanks!

      • aaronL333 June 7, 2017 at 9:04 pm #

        Hi John,

        I interpreted it as follows:

        Delete the detail record
        Later, separately delete the master record
        You wouldn’t be able to simply undelete the detail record since there is no longer an active master record to relate it to

        What if you were to undelete the master record first and then undelete the detail record? Would that work since you would now have a master record to relate it to? Or is the relationship severed permanently upon initial deletion of the master record?

        I am getting a lot out of this site, by the way. Thanks for your efforts!!!

        • JohnCoppedge June 7, 2017 at 9:36 pm #

          I would definitely need to test that scenario out 🙂

          Good question but not sure. I suspect that it would recover the relationship (b/c when you delete the detail record it would have stored the id of the master at the time of deletion of the detail record)

  5. nk005347 October 10, 2016 at 8:18 am #

    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

  6. nk005347 October 10, 2016 at 7:55 am #

    Below statement is bit confusing(https://help.salesforce.com/HTViewHelpDoc?id=overview_of_custom_object_relationships.htm&language=en_US).
    ” To prevent records from being accidentally deleted, cascade-delete is disabled by default. Contact Salesforce to get the cascade-delete option enabled for your organization.
    Then what is meaning of “Delete This Record Also” option in look up relationship?

    Regds
    Nikhil

  7. bijunarayanan August 23, 2016 at 8:01 pm #

    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

    • nk005347 October 5, 2016 at 3:35 pm #

      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

      • trpbt December 2, 2016 at 6:25 am #

        answer seems correct to me. John request you to please confirm the limitation of lookup field in this case. Thanks!!

  8. sanfranmovers August 19, 2016 at 8:11 pm #

    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

  9. sanfranmovers August 19, 2016 at 7:59 pm #

    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

  10. jobzmpons@hotmail.com June 14, 2016 at 2:13 am #

    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?

    • JohnCoppedge June 14, 2016 at 6:29 am #

      Hence why I suggest not using other sites- you are correct, the site’s answer is incorrect (answer is false).

      Years (5 maybe) ago that used to be the case, however.

  11. Firstrock June 4, 2016 at 12:21 am #

    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

    • JohnCoppedge June 5, 2016 at 5:54 pm #

      Ah standard to standard would have to be a relationship created by SalesForce, not one that you created

    • syninaptic December 17, 2017 at 2:04 am #

      look at the date of the information to see if it is up to date

  12. Firstrock June 3, 2016 at 9:18 pm #

    Can we have a master detail relation ship between 2 standard objects?

    • JohnCoppedge June 3, 2016 at 10:41 pm #

      You cannot create a master/detail relationship where the standard object is the detail- in short, no

  13. tejalr8@gmail.com November 30, 2015 at 3:48 am #

    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?

    • JohnCoppedge December 1, 2015 at 1:33 am #

      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.

  14. msmith630 November 14, 2015 at 4:20 pm #

    so a year from now(winter 2016), the total of roll-up summary per custom and standard object will be 25?

  15. mynameisaron October 25, 2015 at 6:56 pm #

    4:32 The limit is no longer 10 roll up summary fields, its 25.
    http://www.adminhero.com/getting-cozy-with-the-winter-16-release/

  16. Jake Schmitz July 16, 2015 at 1:05 am #

    Just a fun fact: this is a great resource for anyone trying to overcome the standard limitations. It has worked well in all my orgs so far! http://andyinthecloud.com/2013/07/07/new-tool-declarative-rollups-for-lookups/

  17. MikeSabel June 15, 2015 at 6:49 pm #

    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?

    • MikeSabel June 15, 2015 at 6:50 pm #

      John, I added this comment to the wrong video. I’ll copy and paste it to the correct video now. Thanks.

    • JohnCoppedge November 9, 2015 at 5:44 pm #

      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.

  18. Patty Macdonald December 23, 2014 at 3:09 am #

    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)

    • JohnCoppedge December 23, 2014 at 3:16 pm #

      Lookup and master/detail relationships are fields that establish relationships between objects. Hope that clarifies

  19. Mike Callaghan September 15, 2014 at 2:16 am #

    Just as an FYI, you can request SalesForce to increase the number of rollup fields available for a specific object to 25.

    • JohnCoppedge September 27, 2014 at 7:32 pm #

      Good point – that is a soft limit. To my knowledge there is no good resource that outlines what’s a flexible versus inflexible limit.

  20. Elizabeth Locke June 25, 2014 at 2:47 pm #

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

    • JohnCoppedge July 16, 2014 at 5:08 pm #

      Correct- this is an exception. The standard objects do not follow all of the rules exactly as they would be applied to custom objects.

Leave a Reply