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
Jeff C.ax327Jeff C.ax327 

Multiple detail sections with different standard controllers?

I have a custom object with a 1-to-1 relationship with the Contact object via a lookup field.  I want to create a Visualforce page that shows the Contact detail section on top and the customObj__c detail section below it.  I know that I could work around it by using the Contact standard controller for the page and then lay out my custom object's fields by hand, but it would be fantastic if it were possible to do this using standard controllers for both, since that would allow the page layout tool to be used (and different layouts per record type, etc).
 
I'm still pretty new to Visualforce and custom controllers, extensions, and components.  I thought maybe I could get this to work by putting an <apex:detail> section in a custom component.  The first problem is that it appears there's no way to have a component use a standard controller.  Secondly, when the component is included in the main Contact page, the <apex:detail> section takes on the scope of the Contact record, rather than pull from the controller of the component.
 
I guess I'm essentially trying to put together a sort of "Console" type of functionality where multiple detail sections are present and they relate to the main Contact record.  Is this possible using Visualforce?
 
Thanks,
Jeff
 
Mark YoungMark Young
Take a look at the subject property of the detail component.  This can be an id of any type and the correct detail view will be used (regardless of controller).
kevinedelmannkevinedelmann
This looks like what I am looking for as well, though I am really new to VF.  Would it be possible to type out a quick example line of how this would look?
Jeff C.ax327Jeff C.ax327

Thank you for your reply, Mark.  The method you describe works great.  However, I just noticed a side effect that I can't seem to work around.  The title & subtitle of the page seems to always take on the values for the object whose detail section was specified last.  The top of the page should display a title of "Contact" and then the contact Name as the subtitle.  Unfortunately, when I include a second detail section from a custom object, the title displays the label of my custom object and the subtitle displays the Name value from the record from my custom object (which is a meaningless Auto Number).

Code:
<apex:page standardController="Contact" extensions="controllerCustomContact" action="{! initCustomContact }">

   <apex:detail relatedList="false"/>
   <apex:detail relatedList="true" subject="{! myRelatedObjectId }"/>

</apex:page>

 As as test, I added a third detail section (another standard one with no subject attribute) after the custom one, and then the correct Title/Subtitle is displayed again.  So it sure does seem that it uses the object/record from the final detail section.  Any way around this?
 
Thanks,
Jeff

 
JoshVHJoshVH
I'm seeing the same behavior.  Any update on how to get around it?
Jeff C.ax327Jeff C.ax327
No, I'm sorry, I still have not resolved this.  I don't see a way around it and haven't heard from anyone else.
JoshVHJoshVH
Have you submitted it to developer support?  If you don't have developer support let me know and I will submit it.
Mark YoungMark Young
Hi guys,
 
I don't have an environment to test this in at the moment, but have you tried adding an <apex: sectionHeader> to your page?
Jeff C.ax327Jeff C.ax327

Hi Mark,

Adding a section header just... adds another section header.  The default detail header is still there.  I haven't taken the time to submit this to premier support just yet...  but I guess I really should...

JoshVHJoshVH
I have.  It just adds it below the default section header.  For instance, the code below displays a second sectionHeader below the one that contains information for the second apex:detail tag.  So the first sectionHeader contains information about the object in Task.WhatId and the second one says Task as I have added it below.

<apex:page standardController="Task" showHeader="true" tabStyle="task" title="Task" >
<apex:sectionHeader title="Task"/>
    <apex:detail subject="{!Task.Id}" >
    </apex:detail>
    <br/>
    <br/>
    <br/>
    <br/>
    <apex:detail subject="{!Task.WhatId}">
    </apex:detail>
</apex:page>
Mark YoungMark Young
Okay,
 
So I've whipped up a quick test.  Try setting
Code:
title="false"

on the detail controls that you don't want to show the title (or all if you want a custom title).
 
Mark 
JoshVHJoshVH
I just figured it out.  You have to set the title attribute to false on the second detail section to get the first detail section to control the title.  See code below.

<apex:page standardController="Task" showHeader="true" tabStyle="task" title="Task" >
    <apex:detail subject="{!Task.Id}" >
    </apex:detail>
    <br/>
    <br/>
    <br/>
    <br/>
    <apex:detail subject="{!Task.WhatId}" title="false">
    </apex:detail>
</apex:page>
JoshVHJoshVH
Looks like we discovered it at the same time.  Thanks.

Josh
Jeff C.ax327Jeff C.ax327
Ahh... thanks guys. I just tested that and it works. Could've swore that I tried all those variations, but alas... Glad it works now, thanks again!