You need to sign in to do that
Don't have an account?
Rendering mutiple records with related lists
I need to create a document (ie a nice looking deep report) that contains all the records from a custom object including each record's related lists. I've tried using the new reports to get the data but they are limited to three objects, and I can't get CongaMerge to do it because their SOQL (Conga Query) doesn't support sub selects.
One person suggested to send a visualforce page a list of Id's in the URL (or have the controller look up a list of sobjects) and use the apex:repeat and apex:detail tags to render the records as this would use the object's page layout and include the related lists, voila!
But I'm falling over at the first hurdle: I just can't get the page to render multiple records.
Attempt 1 (Url is /apex/mapPage?id=XXXXXXXXXX,XXXXXXXXX,XXXXXXXX) The result is the detail tag complaining that it can't accept "XXXXXXXXXX,XXXXXXXXX..." as an ID, so clearly I've not wired up the repeat variable and detail tags correctly.
<!-- Page --> <apex:page controller="DominoController" id="thePage"> <apex:repeat var="string" value="{!strings}" id="theRepeat"> <apex:detail /> <hr/> </apex:repeat> </apex:page> /* Controller */ public with sharing class DominoController { public String[] idS{ get; set; } public DominoController() { String[] idS = ApexPages.currentPage().getParameters().get('id').split(','); /* This successfully gets me a string array of id's */ } }
Attempt 2 (Id's are looked up using a select statement in the controller and put into "oList" but I can't get the detail tag to take the list items, I just get the same nothing repeated X number of times - note the rerender attribute is just a desparate attempt)
<!-- Page --> <apex:page controller="DominoController" id="thePage"> <apex:repeat var="o" value="{!oList}" id="theRepeat"> <apex:detail rerender="{!o}"/> <hr/>Line break<hr/> </apex:repeat> </apex:page> /* Controller */ public with sharing class DominoController { public List<sObject> oList{ get; set; } public DominoController() { soqlQuery = 'select id, Name from MyCustomObject'; oList= Database.query(soqlQuery); /* This successfully gets me a list of objects */ } }
Heeeeeelp!
Thanks bob!
Using the subject attribute correctly was the key. I guess I overlooked that in the documentation. I still didn't manage to use the ids from the URL, but I worked around that by having a parent custom object have some set up fields that I use to build a custom query (which is a more extensible solution anyway and one I can build a siple interface for my bussiness users in).
The next thing I will do is to get the output as a PDF and do some styling to make it more readable.
Wokring sample code was (with all the fancy stuff stripped out) this:
I now have a very powerful and easy way to mass extract data from my salesforce instance ready to print!
If anyone has some tricks on rendering a visualforce page into word document format that would be a good link to post on this topic.
All Answers
In attempt 1, the apex:detail tag will attempt to derive the ID from the URL. You'll need to iterate your ids list and tell the detail tag to use the iterator value instead.
E.g.
See how you get on with that.
Thanks bob!
Using the subject attribute correctly was the key. I guess I overlooked that in the documentation. I still didn't manage to use the ids from the URL, but I worked around that by having a parent custom object have some set up fields that I use to build a custom query (which is a more extensible solution anyway and one I can build a siple interface for my bussiness users in).
The next thing I will do is to get the output as a PDF and do some styling to make it more readable.
Wokring sample code was (with all the fancy stuff stripped out) this:
I now have a very powerful and easy way to mass extract data from my salesforce instance ready to print!
If anyone has some tricks on rendering a visualforce page into word document format that would be a good link to post on this topic.
replying to my own post. this blog post covers outputting as word / pdf / excel which very nicely rounds off this thread
http://salesforcesource.blogspot.com/2009/04/how-to-create-word-pdf-or-excel-files.html
So if anyone follows this conversation you now know how to create detailed mass exports of your data into documents your bussiness users will enjoy reading and editing!
Have fun!
Hi,
Thanks for the post. Good example. My requirement is to build something in similar lines but the other way.
I need to display the parent detail page with the detail pages of all the related lists in a single visualforce page (Not worried about the length of the page)
Ex: I have myCustomObject__c as a related list under Account.
I would like to display Account detail which I can capture in <apex:detail subject="{!Account}" > and passing the ID. Along with this, I need to add the <apex:detail > of the related records as well. I tried <apex:repeat> as explained in this post. That doesn't work. It is giving me blank page.
Please let me know where have I gone wrong?
Update:
I have got partial solution. Removing the WHERE condition from SOQL query gives me the detail view of all the records in MyCustomObject__c of all the Accounts.
Two things to worry about
FIRST:
I need only related records of the particular Account. If I add where condition, I am getting the following error:
unexpected token: 'O00000074Mr8IAE'
An unexpected error has occurred. Your development organization has been notified.
The ID mentioned here is the Account ID of the record I am trying to open.
SECOND:
If I add renderas="PDF" to the apex tag. It is giving me weird results even without WHERE Condition.
The output is something like this . problem with encoding ?
%PDF-1.4 %���� 2 0 obj <>stream x�c endstream endobj 5 0 obj <>stream x��老�Q�lp1+@@4��ьĬ2�`�L��̊F�6E�aNN��U� J�P����bpQ�s���e@&��SM 1��d��<���LjQ&cM�����5��\D����4���ڐ2�q��h���L��|����>�-ZF��Q���?���eJ�"�%9��w����u�Hug ;����l��WްxBSN�2zsZ�yMn��M���YQ���������b�nR~'�2/�!2W��4��r�m� ��J�����5p�%�����ͺ^�E�hq�
Help.
Accordng to the visualforce developer's guide, best practices for rendering PDFs, the <apex:detail/> component is not safe to use in pages rendered as PDF, so weird results are to be expected.