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
JAW99JAW99 

Adding custom objects tabs to Tabbed Account

I followed this demo but can't list custom objects in the tabs.
If my custom object is "Transfer Station" and is child to Account in Master - Detail relationship, how do I code this?
I was able to figure out Closed Activities, Contracts, on my own, but beyond that, no custom object.
Code:
 <apex:tab label="Open Activities" name="OpenActivities" id="tabOpenAct">
         <apex:relatedList subject="{!account}" list="OpenActivities" />
      </apex:tab>
 <apex:tab label="Closed Activities" name="ActivityHistories" id="tabClosdAct">
         <apex:relatedList subject="{!account}" list="ActivityHistories" />
      </apex:tab>

 
Those work. How would Transfer Station get in there? Thanks in advance!

JimRaeJimRae
You do it the same way as you do with the standard objects, but you reference the custom object relationship name.
You need to use a tool that can browse the schema, like AJAX Tools Explorer, or something like that.
You will see "Child Relationships" under your Account object, and in addition to the standard ones, you will see one, or more with names that look more like id's, (like this, for example: R00N700000028OnJEAU ), once you determine which one represents your Transfer Station object, you can put it in the same way.
 
Code:
<apex:tab label="Transfer Station" name="TransferStation" id="tabTransferStation">
         <apex:relatedList subject="{!account}" list="R00N700000028OnJEAU" />
      </apex:tab>

Good Luck!!
JAW99JAW99
Got it! Thank you very much.
JAW99JAW99
Jim,
Interestingly, I have some custom objects who don't have this long ID string relating them, but instead I relate it with just  "Customobject__r" (example below).
I'm curious why this is so. Any ideas?
Code:
<apex:tab label="Dreadnoughts" name="Dreadnoughts" id="tabDrdNgt">
      <apex:relatedList subject="{!account}" list="Dreadnought__r" /> 
      </apex:tab>

JimRaeJimRae
Not sure why it doesn't always do this, but you can add a name to the relationship on your lookup field.  If you edit your child objects related lookup field, you can specify a "Child Relationship Name".  Just give it a regular name, and the __r gets appended as the api name.
In your example, you would name it Dreadnaught and the API name would be Dreadnaught__r.
Does make it more readable, I actually just updated one of mine when I figured that out.
 
 
JAW99JAW99
Excellent - thanks, Jim.
I noticed that putting tabs in for custom related lists that users don't normally see in their layout stops the loading of the VF page at that list.
I can't see how I'd use this tabbing then. It would be great b/c our acct page is fairly long, and there's up to 15 related lists.
JimRaeJimRae
Don't know about that one.  Could it be that the user doesn't have access to the objects in the related list at all?
JAW99JAW99
Nope, it's simply whether or not that related list is on the user's assigned page layout.
I checked it all again and did a test or two. The user has read and edit permission for the object, but if the list is not on the assigned page layout, the VF page will not load, giving:
 "(related list id)  is not a valid child relationship name for entity Account

It leaves me lost for use of tabbed account page. Maybe it's possible to customize the VF page based on profile...?
JimRaeJimRae
I don't see why you couldn't customize based on profile.  You would need the custom controllers constructor to determine the running users profile, then set the visibility of the tabs (rendered=true) based on the result. 
 
Use a merge field on the tab line to set the flag:
Code:
<apex:tab label="Draughtnut" name="draughtnut" id="tabDraugh" rendered="{!showDraught}">

You could test this quickly by setting the rendered flag to false on the tabs that your test user doesn't have visibility to and see if the whole page loads.

 
 
JAW99JAW99
I think i was wrong before. I think the issue may have been that the object was not yet deployed.
I'll have to check it out further to make sure I'm getting the whole picture.
JAW99JAW99
That the object was not deployed was indeed the issue.
Alas, my apex explorer is acting up and I can't get back in to find out other ids, custom, or Account History... argh!
JAW99JAW99
So how can i add the acct history - my explorer shows the relationship name is "Histories" but this produces the usual error: not a valid child relationship name for entity Account

JimRaeJimRae
Did you mean Activity History?  I don't have an Account History relationship, but I do have an Activity History relationship called "ActivityHistories".
JAW99JAW99
Jim
Not Activity History, I got the completed activities in there. I mean the account field history. I'd like to get that in.
Big ChewyBig Chewy
Hi all,

I'm having the same problem that you have had in the past but unfortunately what you have done doesn't seem to be working for me.  I have a custom object Back_Office_Patient__c with a child object Medical_Record__c.  When creating a VF page I can't get the Medical_Record__r to show up, instead receiving the typical error message you have seen:  'Medical_Record__r' is not a valid child relationship name for entity Back Office Patient.  I have tried to put other standard related lists in and have some luck ("ActivityHistories" and "Open Activities" work) but not entirely ("Histories", "Events", "Tasks" don't work).  My other child relationship doesn't work either.  I downloaded the Enterprise WSDL and looked through the Back_Office_Patient__c section for all the elements of type "QueryResult" (based on suggestion from another thread).  Neither of my Child Relationships exist in this section but all the standard objects that both work AND don't work are in there!

Additionally, I reviewed my salesforce schema via Apex Explorer and I see the child object.  It says "Child Object: Medical_Record__c" (which of course doesn't work).   It also has a relationship name: [what looks like a GUID] but I can't copy and paste it.  I wrote it down and am confident I did it correctly but that ID did not work either.  my syntax is:

This works:
        <apex:relatedList list="NotesandAttachments" id="b"> </apex:relatedList>   

These do not work:
        <apex:relatedList list="Medical_Record__r" id="b"> </apex:relatedList>   
        <apex:relatedList list="Medical_Record__c" id="b"> </apex:relatedList>   
        <apex:relatedList list="R00N40000001|znqEAA" id="b"> </apex:relatedList>   

I'm completely out of ideas at this time.  Any thoughts?

Thanks

Eric
Carl_V1Carl_V1
Just out of interest, is the related list you're trying to view actually present on the page layout that would typically be seen by the user? If it isnt, try adding it then see if the related list becomes visible...
CTU007CTU007
Hi, has anyone been able to add the "account history"? I also got error msg saying it is not valid child relation name.
 
 
 
 


JAW99    That the object was not deployed was indeed the issue. Alas, my apex explorer is acting up and I can't get back in to find out other ids, custom, or Account History... argh!


Message Edited by CTU007 on 12-31-2008 06:15 AM
biggieBbiggieB
I'm having the same issue on standard and custom related lists.  All custom objects have been deployed and all desired related lists are on the standard Account page layout.  Any ideas why I get this error:   'Contacts' is not a valid child relationship name for entity Account

 My code is below.

<apex:tab label="Contacts" name="Contacts" id="tabContact">

         <apex:relatedList subject="{!account}" list="Contacts" />

      </apex:tab>




Message Edited by biggieB on 01-18-2009 04:55 PM
jenbryant39jenbryant39

Hi folks,

 

I ran into same issue regarding  "Contacts" related list.   If you have person accounts enabled and the record is of type person account then this related list will not work.  I believe it only works where you have business accounts.  In order to link contacts to Person accounts what I did was create a master detail relationship on the contacts object and called it "Member Contacts"  then added a Member_Contacts__R related list.  

 

As for Account History .... I still cannot get that to pull in as a related list.  I've tried List="Histories" which is not working.

CTU007CTU007

This works for me to add a link to the account field history:

 

<apex:tab label="Field History" name="Field History" id="fieldhistory" rendered="{!$Profile.Id!='00exxxxxxxxx'}" >
         <apex:outputLink value="https://ssl.salesforce.com/_ui/common/history/ui/EntityHistoryFilterPage?id={!account.id}">
            click to view field history
         </apex:outputLink>
       
      </apex:tab>

 

Not optimum as user has to click the link but you dont need to do a lot of work. 

chrissy111chrissy111

CTU007's link idea does work well.  I also figured out how to access the Account History data.  It is NOT a related list.  Instead, use the code <apex:dataTable> to pull from the account.histories table.  Below is rough code that will pull the Account History into a separate tab.  The HTML formating is not very clean, but the data query works!:

 

<apex:tab label="Field History" name="Account History" id="fieldhistory" >  
    <apex:dataTable value="{!account.histories}" var="accounthistory" id="HistTable" rowClasses="odd,even"
                        styleClass="tableClass" cellspacing="15" width="80%">
                <apex:facet name="caption"></apex:facet>
                <apex:facet name="header">Field History</apex:facet>
                <apex:facet name="footer"></apex:facet>
                 <apex:column>
                        <apex:facet name="header">Edit Date</apex:facet>
                        <apex:facet name="footer"></apex:facet>
                        <apex:outputText value="{0,date,MM/dd/yyyy HH:mm }">
                            <apex:param value="{!accounthistory.createddate}" />
                        </apex:outputText>
                </apex:column>
                <apex:column>
                        <apex:facet name="header">Field</apex:facet>
                        <apex:facet name="footer"></apex:facet>
                       <b> <apex:outputText value="{!accounthistory.field}"/></b>
                </apex:column>
                <apex:column>
                        <apex:facet name="header">Edited By</apex:facet>
                        <apex:facet name="footer"></apex:facet>
                        <apex:outputText value="{!accounthistory.createdby.name}"/>
                </apex:column>
         <apex:column>
                        <apex:facet name="header">Old Value</apex:facet>
                        <apex:facet name="footer"></apex:facet>
                        <apex:outputText value="{!accounthistory.oldvalue}"/>
                </apex:column>      
        <apex:column>
                        <apex:facet name="header">New Value</apex:facet>
                        <apex:facet name="footer"></apex:facet>
                        <apex:outputText value="{!accounthistory.newvalue}"/>
                </apex:column>
        </apex:dataTable>
  </apex:tab>

jaw999jaw999
To keep this relevant for the mobile is everything mania surrounding SF these days, just make your VF page NOT available for mobile and you can use this tab account view (Great for reducing the endless scrolling of Chatter) and SF1.