Forgive me, I just started Salesforce development this week so I don't know many of it's methodologies and idiosyncrasies yet.

Let's say I need a Custom Object to represent computer parts individually while also representing a complete computer, that has list of all of its parts (I'll be using this list to automatically calculate prices and profitability).

i.e., for each "Product" I need to be able to select all of the "child" parts (also Products) that make up the whole assembly/computer. I think I'm looking for a Multi-Select Lookup Relationship, but that doesn't seem to exist.

I understand how to easily accomplish this in a traditional RDBMS, i'm not sure it'd be the best approach to take in Salesforce -- that and I don't know how to represent this in the UI.

What is the canonical Salesforce way of accomplishing this and can it be done without using a Visualforce Page?

  • Unless you have some other dependency, you may be better off using all custom objects rather than the standard Salesforce Product object. Jun 13, 2015 at 0:11
  • We're actually using a managed app and trying to extend its functionality. Jun 15, 2015 at 13:42

2 Answers 2


Many to Many Relationships are accomplished by using what is known as a Junction Object.

The "Junction Object" has one Master/Detail lookup relationship to the "Product" and one Master/Detail lookup relationship to your "Parts" Object.

Thus you would ultimately have Three sObjects accomplishing what you want.

Some documentation to help you out

  • Sorry I wasn't clear, there is only one (non-junction) object, Product. Salesforce won't let me create a two Master-Detail Relationships to the same Custom Object (as fields in the same object), like the documentation you linked to states. Also, I'm not sure how to set this up in the UI, as there is no Multi-Select Relationship Field available. Jun 12, 2015 at 19:58
  • @DavidMurdoch it sounds like you may be misunderstanding how Many To Many relationships work. You create the junction object with the sole purpose of relating the Product & Parts records to each other, numerous times. The Master-Detail lookup fields are added to that junction object and when both master records are looked up, from a junction object record, you've established the relationship. You create a junction object record from either master record, each time you want to relate that record to the other object's record.
    – Alex S
    Jun 12, 2015 at 20:06
  • 1
    I fully understand m2m from a CS and pratical standpoint, I'm just not sure how to get the Salesforce UI to display it as wanted. I think the disconnect for me is that I don't know what Salesforce is capable of (without using Visualforce). What I'm looking to do in the UI is this: imgur.com/gRvjShB, where the items in the circled picklist are Products themselves. Jun 12, 2015 at 20:26
  • @DavidMurdoch Got it, it's definitely not standard functionality unfortunately success.salesforce.com/ideaview?id=08730000000Br8cAAC. PS you need to tag commenters when you reply to them, Doug with receive a notification for each of your comments but I wouldn't unless you use @...
    – Alex S
    Jun 12, 2015 at 20:51
  • @DavidMurdoch the other challenge you face is that even with VisualForce, you can't populate the same lookup field with multiple records..success.salesforce.com/ideaView?id=08730000000KQyHAAW
    – Alex S
    Jun 12, 2015 at 20:58

I think what Doug is describing is to use separate objects for the Product and Part and for the junction object (called Use here):

many to many relationship

Then without Visualforce you can show all the parts used by a product in the product's related lists and all the products that reference a part in the parts related lists. You can also add or delete the junction objects from either side.

  • Is it possible to accomplish something like the following in a Product's edit view? imgur.com/gRvjShB I'd like to be able to configure the relationships between parts from within the product edit view. Jun 12, 2015 at 20:48
  • 1
    @DavidMurdoch The 'related lists' part of the Product page layout is the default way to add/remove related objects. Those aren't technically part of the 'edit' view, but can be handled from the Product page layout. An existing example of this would be how you can add 'Products' (the standard SF object) to Opportunities, as those two objects also have a many to many relationship (their junction object being 'Product line items')
    – smohyee
    Jun 12, 2015 at 21:07
  • 1
    @DavidMurdoch Yes, you can add Use as a "related list" to the product detail page and display fields from both Use and Part there. Create the objects and try it - will only take a few minutes. By using objects (=tables) you can add fields in the future as needed.
    – Keith C
    Jun 12, 2015 at 21:09
  • That feature looks great... now my only problem is that Salesforce (arbitrarily?) restricts an Object from having two Mast-Detail Relationships to the same Object. I guess I'll just have to clone my Products Object and write some triggers that keeps the clone and the Product object in sync. Jun 12, 2015 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.