+ Start a Discussion
cnp_nareshcnp_naresh 

How to get related list fields in apex

HI Everybody,

 

    I have a new requirement in my project. My requirement is I want to customize related list.For a custom object we will have a page layout.In that page layout I can add related lists.If I drag and drop this related list in layout I can see this in detail page of record of that custom object. 

Now how can I get the fields of that related list in apex code. If I get these fields in apex code, I can display them in visualforce in a very customized way.

 

If you need any more information please let me know.

 

   Kindly help me.

 

Thanks,

Naresh B

sfdcfoxsfdcfox

As far as I am aware, there is no mechanism by which you can retrieve the fields in the related list purely through Visualforce and Apex Code. Any attempted solution would require asynchronous access with the ability to download and extract a ZIP file, read the file's contents, decompress the appropriate layout, and process the XML code for that layout. All in all, you're looking at a lot of work for your feature, but it does sound like a very intriguiging idea. Hopefully, an upcoming release will provide the R in CRUD-based metadata API access, as this would make it feasible to attain what you're trying to do.

vriavmvriavm

Hi,

      If I understand correctly all you need is retrieve the related list in the controller.

 

     Why dont you query the related object with the parent ID and get all the required fields.

 

     Please provide more infromation if I am not understanding it right.

 

cnp_nareshcnp_naresh

HI Friend thanks for your reply.

 

    I understood your solution. But the problem with this solution is, if the user want to display some more fields in related list, then again I need to change the query. So I want to get the user selected fields from page layout.So fields will be automatically updated.

 

Thanks,

Naresh B