14

I checked 'Account Name' field in Contact object. It appeared as a Lookup(Account). But when I deleted that account, contact also got deleted which tells me it is a master-detail relation. Can anyone explain me the proper way to explain the relationship between account and contact?

7 Answers 7

21

There are four different kind of relationships in the force.com platform.

But I like to categorize them in a slightly different way than the help pages:

  • Lookup
  • Master-Detail
  • Hierarchy
  • Standard relationships

There are lot's of help topics and articles on Lookup and Master-Detail, such as the relationship overview and the relationship considerations topics in help. I don't like including Many-to-Many in this kind of discussion because, for all intents and purposes M:M is just an implementation of two M-D relationships (by strict reading of the docs), or possibly two lookup relationships or a mix of the two.

To dispense quickly with hierarchy relationships, these are a special lookup self-join relationship on the User object. Read up on those on your own. :-)

So let me talk about my own invented fourth category.

Standard Relationships

If we (salesforce.com) provide you with a relationship between two objects, that is a standard relationship. Not lookup, not master-detail. Why do I bother providing this fourth category? Because it is the easiest way to stop people trying to categorize them as either lookup or master-detail when they often share characteristics of both. When you approach working with any standard relationship the question you really need to answer is, "how does this standard relationship behave." Frequently standard relationships have characteristics that you just can't do with a custom relationship. Ever tried to make a custom relationship polymorphic? Go ahead...give it a try. You will fail. But there are many examples of polymorphic standard relationships.

I like to categorize these in their own separate place independent of lookup/master-detail. In fact, anything standard follows the same rule: it behaves exactly the way that salesforce.com wants it to behave to fit the particular purpose of that standard thing.

In my opinion, the Account-Contact relationship is a perfect justification for this fourth category: it is a little like lookup, a little like Master-Detail, but fundamentally behaves the way it does because we decided it should.

That might not be the "proper" way, as you ask, but it is the one that makes the most sense to me.

1
  • Couldn't have got a better explanation. Thanks @peter
    – MnZ
    Apr 16, 2014 at 7:48
11

Contacts and Accounts have a lookup relationship but this relationship has a property called CascadeDelete set to true. This is why the contact is deleted when the parent object is deleted. enter image description here.

4
  • Is CascaDedelete available for custom object lookup relationships? I hope its not a silly question, I'm a beginner :)
    – MnZ
    Feb 24, 2014 at 13:53
  • No, you cannot set that property in a custom lookup relationship.
    – PepeFloyd
    Feb 24, 2014 at 15:53
  • 2
    Actually, cascade delete is an option in a custom lookup relationship, but you must contact support to enable this feature. There are important considerations around cascading a lookup relationship in that a user might cascade a delete to child records that they normally wouldn't have access to even view. Please read the help topics on relationships for more about this.
    – pchittum
    Feb 24, 2014 at 17:10
  • @pchittum : Can you please help ? salesforce.stackexchange.com/questions/386763/… Oct 3, 2022 at 15:44
3

Account and contact behaves as master detail in business logics but on UI it is a lookup relationship. Let me explain you a bit more.

You can create a contact without filling account i.e it shows that there is a lookup relationship between account and contact.

If you have created a contact with account and you delete that account then contact will be deleted, this shows that it is in Master-Detail relationship. This is a standard behavior.

So we can say it in both ways, but it documentation it is a lookup relationship.

1

Account and contact have a lookup relationship. It is lookup because you can create a contact without account. However it behaves weird –like master detail in business logics – when you create a contact with account and you delete that account then contact will be also deleted.

But it documentation you can find that this is a lookup relationship.

1
  • Took almost a year to reply, better late then never, Thanks!
    – MnZ
    Feb 5, 2015 at 8:47
1

Account and Contact behaves as master-detail but on UI it is a look-up relationship. This is because of business implementation.

Account comes from Opportunity. Suppose you Sale some product. You reach to a person and he fixed some deals with us, By this It becomes an Opportunity. Now that Opportunity purchased some products with you organization. Now he becomes an Account. After that Account reference some contacts with whom your organization can process deal. Now those reference are your organization Contact.

In this case if that Account is no more purchasing products and can not continue with your organization. In that case you delete that account and it makes sense that their related contacts must be deleted. That is why this happens.

Contact without Account as a parent are private and cannot be seen by other users in an organization. Because they are your personal contact persons like you have in your cell phone.

1

Just to add, another thing where you might get confused w.r.t. account and contact is - if you change the owner of Account record, Contact OwnerId changes. However, when you do the same via code, you have to manually change the Contact owner. So, as everyone said, it is a lookup but internally works like master details.

1

Account and contact have a special lookup relationship with the cascade delete option on.

You could create your own custom special lookup relationship by openning a case to the support.

Check this knowledge article for more information.

https://help.salesforce.com/articleView?id=000313755&language=en_US&type=1&mode=1

You must log in to answer this question.

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