Thursday, September 16, 2010

Combine Related List of Same Object to display as one List

Merging Related List for the same object (Part 1)

One of the most popular issues that people face during implementation is managing related list of the same object. doesn't provide an out of the box way to combine related list from the same object for two or more Lookup fields. I faced the same issue during several implementations where client asked me to combine the related list in to one list.

To overcome this challenge you will need to customize to merge the two related list records. 

I am going to use an example posted on Ideas and show you a way to resolve this issue.

"I have two custom objects, Lab Projects and Employees. Any given Lab Project always has two Employees assigned, using lookups, and Employees can change roles between projects (Lead one time, Support the next). (Top image) This causes two separate related lists to show up on an Employee's page. (Middle image) It would be great if I could combine these two lookups on the Lab Project to appear in one combined related list on the Employee page. (Bottom image) Note: This should only work when dealing with multiple lookups on the same data type. source ("

While I was reading through the post on Ideas I did see that people were discussing that there is no resolution to maintaining many to many relationship between two objects. You will ALWAYS NEED A THIRD OBJECT for maintaining the relationship in any data structure model whether it is on the cloud or on premise solution or even if you are using a simple database structure like Access or complex data model such as Oracle or MSSQL Server,. However there are creative ways on how you can overcome this seamlessly in the user interface.

if you need to associate more than two Employees to the Lab Project object then simply create a "Junction / Connector" object. However if you only have two fields and you would like to maintain a single related list then please proceed ahead.

In this post I will give you a brief overview on how to combine the two related list. In part II of this post I will show you in detail on how to implement this solution. 

In Part II I tend to cover some of the more complex customizations such as writing apex trigger, creating a custom button etc.


Step 1: Create a third object called "All Analyst." Make sure that you make the record name Auto Numbered.

Step 2: Create two Lookup fields on the newly created object and a Text field with 255 characters

  • Employee (Lookup - Employee object)
  • Lab Project (Lookup - Lab Project object)
  • Role (Text - To store the role of the employee)

Do not show the "related list on the Lab Project Page Layout.

Step 3: Develop a trigger on Lab Project to create a record on the junction object.

Step4: Adjust the employee page layout as shown below by removing the related list created by adding the lookup fields on Lab Project object. Replace "New All Analyst" button with your custom button.

Why do you need to replace the button on the All Analyst related list: 

The out of the box button when clicked will create a junction record between employee and the lab project. User may require to directly create a lab project record directly from the employee page. 

For example, when you are on Jane Doe's record you can click on a button to create a new Lab Project. We also want to have the ability to choose if Jane Doe is a Lead Analyst or a Support Analyst for this new Lab Project that we are about to create. Hence to create a lab project record from Jane Doe's page w

e need to create two custom buttons, New Lead Analyst and New Support Analyst as shown below.

If you clicked on the "New Lead Analyst" button from Jane Doe's page layout a new lab project will be created which will automatically put Jane Doe on the Lead Analyst field as show below.


  1. Good tip. But where is part 2? :-)

    By the way, you could also accomplish this, without any coding, using a record type, couldn't you? An 'Analyst' object with two record types: 'Lead' & 'Support'. No need for a junction object.

    But I hate to use up record types for such trivial things.

  2. Hi Sri,

    You cannot do it with simply a recordtype if you need two separate lookup fields on the same page layout (unless you build a custom VF ofcourse).

    I was going to put partII and also enhance the blog but I got tied up with work at my current job. I promise to add more content from next month including part2. :)

  3. Hello Rupesh - did you ever complete Part II of this how-to? I would like to see what the whole process is like before considering this.

  4. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    Seo Company in India

  5. Thanks for sharing the useful information about the topic and good points were stated in the blog which is very informative and for the further information visit us at
    Oracle Fusion Financials Training

  6. Thank You For Sharing Information
    Yaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
    Best video editing services in Hyderabad,ameerpet
    Best Graphic Designing services in Hyderabad,ameerpet­
    Best Ad Making services in Hyderabad,ameerpet­