function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ram JampanaRam Jampana 

Visualforce page to display the lookup field's related fields ---- kind of complicated

Hi All.....

I am trying to write a Visualforce page that needs to show some Lookup fields and its related fields.

We have a Custom Object called "Storyboard__c", and this object has to lookup fields

1. Field name: "Origin" , and the lookup object is also same "Storyboard__c", child relationship name is "Origin-Stroyboard"
2. Field name: "Ploting" , and the lookup object is also same "Storyboard__c" child relationship name is "Ploting-Stroyboard"

If I have a record in Storyboard called "Global" and its Origin called "Public Interest" in other words "Public Interest" is also a Storyboard and it will have its own "Origin" and "Ploting"

Now, the Main issue is - As both these fields are lookup fields to the same object I am getting confused and not understanding how to write the controller or class to get the information.

I Need to display in a Visualforce page the three levels of Origin and Ploting details for every story board
                  

file

Hargobind_SinghHargobind_Singh
Hi Ram, 

This seems to be a tree-like structure, where you have a master object, and there are two child objects, one of type = Origin, and one of type = Plotting, and every object then has its own types. 

I suggest you should look at your table structure once, and see if you can change it to just have one self-relationship called "Parent StoryBoard" and use another picklist field for "Type" which can have two values, Origin and Ploting. 

So your record would have a link to the parent, rather than creating links to child records. Having parent record link would ease your queries and would give you more flexibility. Then you can easily write a query to get all records, and then create a collection to show in your page. 

I would not try giving you sample code, until you consider and let me know whether you can change the table structure or not, as it would be more optimum. 




Ram JampanaRam Jampana
Hi Hargobind,

Thank u for a quick response... 

The structure cannot be changed, as it is the key concept of our entire business.

Yes, we can call it a tree structure.. I can create custom lookuo fields and than update the records of thier parent and Grand Parent values with a trigger but this looks too much of dependencies and want to have a cleaner flow.

Any suggestions about the visualforce page ?
Hargobind_SinghHargobind_Singh
Ya, it is complex, to re-confirm, your table structure looks like this:

Storyboard__c object:
Origin__c Lookup(Storyboard__c)
Ploting__c Lookup(Storyboard__c) 

And, the data is being stored in reverse, i.e. The parent object has links to child objects, right ? 




Dev.AshishDev.Ashish
Ram,
Just giving you some pointers, you can use recursion to achieve this.
Try it or let me know if you require help
Ram JampanaRam Jampana
Hi Hargobind....

Yes, the structure is correct....


Ram JampanaRam Jampana
Hi Ashish,

I am kind of new to Apex coding and can you please give me some detail as to how to proceed or a start point or something....

really appreaciate you guys help.....