You need to sign in to do that
Don't have an account?
Combine Two Related List
Hello everyone,
Through searching various past threads it looks like this questions has been asked a few times, however I am hoping to get some specific help.
I've just last week started dedicating myself to learning to develop (SF99!) So I understand this is beyond my range, but this is a need at my current Org, and I thought it would be fun to actually try to do some development.
Note* I understand that a junction object could be an option here. Given the users that will be using these objects, the fewer clicks the better so I need to stick with this model.
We have a Contract Agreement Object that has 5 lookup fields for parties that can be related to the Contract Agreement. On the Party Object, I have 5 list. I would like to combine them into one list, and display them on the Party object. Here is what I have for code so far, I'm a newbie so I'm sure I am far off, but I'm excited to learn.
public class CombineContractAgreement { public CombineContractAgreement(ApexPages.StandardController controller) { } Public List <Contract_Agreement__C> AllRelatedAgreements; Public List<Contract_Agreement__c>GetAllRelatedAgreement() { AllRelatedAgreements = [SELECT id, RecordTypeId, APXT_Redlining_Status__c, APXT_Redlining__Effective_Date__c, Agreement_Name__c FROM Contract_Agreement__c WHERE //Current record is value on any 1 of 5 lookup fields on the Contract Agreement Record.// return AllRelatedAgreements }
Any help you can provide will be greatly apprchated.
Hi Upton,
Sorry, I missed your comment here.
.getRecord() returns the original object and so we need to modify our code a bit to get the Id.
I hope this helps.
All Answers
Hi there,
From what I understood, you'll be on the Party record page and you'll want to see all agreements from 5 different related lists in a single list
Add the lookup field API names in the WHERE clause, but rest all should work.Based on the above, try below code
Thanks a ton Vishal, You're a huge help.
I'm close, but I am getting an error on Line 4
"Incompatible types since an instance of Id is never an instance of SB_Legal_Entity__c"
Thanks Again for all the help!"Party" is actually Legal Entity - API Name SB_Legal_Entity__C. I've tried to search for this issue, but it seems fairly specific?
Hi Upton,
Sorry, I missed your comment here.
.getRecord() returns the original object and so we need to modify our code a bit to get the Id.
I hope this helps.
Hi Vishal -
This is very helpful, I was able to use this and go back and understand why line 4 needed to be updated.
I'm beginning to truly understand how much I don't know. Fun.
Questions:
Okay so I have this class - now I need to create a VF Page or LWC to display it on the Legal Entity Page?
I've searched, and here is the code for the VisualForce component. Can you please let me know if I'm on the right track?
Again, huuuge thanks.Erorr: Line 0 Unknown constructor 'CombineContractAgreement.CombineContractAgreement()'
Hi Upton,
You need to use a Visualforce page here [ideally, a lightning component for Lightning experience, but that would need some hands-on lightning components, so let's start with a visualforce page].
Here's the basic code to start with
You can play around if you wish, here's the visualforce guide to help you : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageBlockTable.htm
Good luck :)
This is awesome - I'm (vishal really) is so close. I tried to build a lwc but I think that will take me a few months to get the handle of. The last question I think is how can I get the name to link to the Contract page. I've tried to plug in an <apex:outputlink> which appears to work, but I'm a little off on the final result. I've gone to this page (https://www.salesforcetutorial.com/outputlink-example/) which suggest I plug in "salesforceinstance.lightning.force.com/{!r.ID}" (included in the code below, but I am reciving an error "Unknown property 'SB_Legal_Entity__cStandardController.r'".
I am assuming that I need to eddit the public class, but I am unsure of how to do that.
Visualforce Page
.vfp
.apxc
Could you please help me link the .Name to the associated record?
Hi Upton,
The error you get is because you're using r.Fieldname which is from the example on the link, whereas on your page you need to use item.fieldname since that's what we have set our var on the page block table.
Try the below and see if this works