Merging Related List for the same object (Part 1)
One of the most popular issues that people face during Salesforce.com implementation is managing related list of the same object. Salesforce.com 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.
One of the most popular issues that people face during Salesforce.com implementation is managing related list of the same object. Salesforce.com 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 Salesforce.com 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 (https://sites.secure.force.com/ideaexchange/apex/ideaview?id=08730000000BqNCAA0)"
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.
Solution:
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.
Good tip. But where is part 2? :-)
ReplyDeleteBy 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.
Hi Sri,
ReplyDeleteYou 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. :)
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.
ReplyDeleteThanks 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
ReplyDeleteOracle Fusion Financials Training
Do you want to know about Nina Marie Daniele Net Worth, early life, biography, age, and relationship status?
ReplyDelete