+ Start a Discussion
laytro1978laytro1978 

how do I display more than one relationship on a visualforce page

So I have a visualforce page that is a redesigned account page layout using a standard controller.

On the page amongst other things I show a list of contact roles in a table.  Some contacts have roles with many accounts .  Ideally I want to show in one column a list of all the other accounts a contact has roles with.

 

For example

 

Name Role Other memberships

Joe Bloggs  Sales ABC Co, XYZ Co, Bloggs Co, etc......

 

I can render the table but can't work out the logic required to show all of the accounts in the other membership column.

 

Any suggestions welcome, thanks in advance.

 

 

Cool_DevloperCool_Devloper

So, basically, you're looking at building a summarized view per contact!

Well, you would need to build a wrapper class for such a custom summarized view wherein you would have a contact and all the related account with roles in one record which you can iterate over in your VF page.

Cool_D 

laytro1978laytro1978

Thanks for the post, I am really looking to have a table on a new visualforce page that is using the account standard controller.

 

The contact role related list tells me which contacts have roles at the account I am looking at.  What it does not tell me is what other roles they have at different accounts. 

 

So I think I need to build a query which returns the various contact roles at an account.  The contact role object contains a lookup to contact.  So with a second query I need to check to see if the contact ids in the first query have other roles and if so retrieve and display them.

 

Very new to apex and vf development can't find a practicle example or sample code to help.  Any suggestions welcome.

 

Cheers 

bob_buzzardbob_buzzard

cool_d's suggestion is the way to go.

 

You'll need a wrapper class, e.g.

 

 

public class RoleWrapper { public Contact contact {get; set;} public List<Account> otherAccounts; public String getOtherAccountNames() { String result; for (Account account : otherAccounts) { result+="," + account; } return account.substring(1); } }

 

Then an account extension controller:

 

 

 

public class AccountExtensionController { private Account account; public AccountExtensionController (ApexPages.StandardController parentController)

{ account = (Account)parentController.getRecord(); }

 

public List<RoleWrapper> getRoleWrappers()

{

// build the role wrapper lists from the account

}

}

 

and you can then use the wrapper in the page:

 

 

  

<apex:page standardcontroller="Account" extensions="AccountExtensionController"> ... <apex:pageBlockTable var="{!roleWrappers" var="wrapper"> <apex:column value="{!wrapper.account.Name}"/> <apex:column value="{!wrapper.account.Role}"/> <apex:column value="{!wrapper.otherAccountNames}"/> </apex:pageBlockTable>