0

I would like to be able to relate two records of the same object to one another. I was thinking of doing this by building a junction object. The junction object would have two lookup fields in it, both to the same object. I would then make a related list in the main object with the junction records in it.

It seems simple enough, but the problem is if I have two fields going to the same object then I believe I would need to have two different related lists in the original object in order to see all of the relevant junction records because in some of the junction records RecordA would be in Field1, but in others it is in Field2. So one of the lists would be showing all the junction records in which the record is in Field1 in a junction record and the other would be to show all the records in which it is in Field2.

Is there a way to do this and only need 1 related list for all the junction records in the original object ?

Thank you.

1 Answer 1

2

Related lists use the child relationship field's relationship name to display values. That means that even though they're the same object, you can't display both records in a standard Related List configuration. Instead, you can choose to either (a) accept that you need two Related Lists on the page, (b) create, update, and delete inverse relationships, or (c) write a component to display this data. It really depends on if you need to report/dashboard/query this data, etc.

8
  • Yha, that's more/less what I figured. Thanks for giving me all the options. The proper solution is obviously "c"....but I might try to figure out a way to do "b".
    – Zoom_v
    May 25, 2023 at 0:07
  • ...or I guess I could just create 2 junction records each time, with opposite field values (each record has one in which theiy're in FieldA) ? And then just build one related list referencing FieldA....? That's a total hack. :-) I think that may be what you're suggesting with "b".
    – Zoom_v
    May 25, 2023 at 0:11
  • 1
    @Zoom_v That's similar to something I've built before. You can do that either in code or declaratively, such as a record-triggered flow. It's not hard to build. You might even include a third field on your junction object so that the pairs can remember each other without having to burn an extra query.
    – sfdcfox
    May 25, 2023 at 0:20
  • I'm probably gonna only have to spend 1 query as it is...but I could be wrong. I intend to build all of this with a Flow button, giving the user selections of records based upon query results. Then I'll create two junction records based on the selection. (one for the current record and one for the selection). Can't think of another query needed...? There may be 1 more I might be overlooking. Regardless, I'm not quite sure what you're saying to do w/ the 3rd field....?
    – Zoom_v
    May 25, 2023 at 0:49
  • 1
    Just a caution - every record you create costs 2k of storage space, so doubling the number of junction objects just for visual presentation could end up consuming a lot of datastore space for little reason.
    – Phil W
    May 25, 2023 at 6:09

You must log in to answer this question.

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