I was recently wondering why Salesforce has not still provided a feature for Master-Detail that makes a view dependent on another one, like Siebel did. What do I mean for a dependent view? I try to explain it with an example.

Let’s say we have two list views, a primary one with all the Accounts and a secondary one with Contacts. When I select the Account X in the primary view, I should see its related contacts in the secondary one.

Dependent List

I’ll show you how to achieve this behaviour with a Visualforce Page. Let’s start by creating a custom controller.

Controller

Its job is to manage the business logic and return the account and contact lists that will be rendered into the Visualforce Page. Account_Contact__c is the controller apex class.

There are three main functions:

  • Account_Contact__c (…) -> its job is to query the accounts and the related contacts, saving them in a Map object (account_contact_Map)
  • getAccountRecords() -> getter method to retrieve queried accounts
  • getRelatedContactRecords() -> getter method to retrieve the account’s related contacts. It exploits the accIdChosen (passed by the Visualforce page) to identify the corresponding element into the Map account_contact_Map

Visualforce Page

It renders the business logic managed by the controller and it is probably the most interesting part to analyze.

I want to dwell on the following details:

  • extensions=”Account_Contact__c” -> It refers to the controller created before
  • <apex:pageBlockTable …> -> It is the table tag
  • <apex:actionSupport event=”onclick” rerender=”RelatedContacts, AccountItems”> -> Each column has the actionSupport tag. It listens to the “onclick” event and it rerenders the RelatedContacts table and the AccountItems table after having updated the accIdChosen attribute (see class controller) with the id of the item selected. The accIdChosen attribute is used for two scopes:
    • To highlight the selected AccountItems table’s row (styleClass=”{!IF(accIdChosen == a.Id,’ui-selected’,”)}”)
    • To get the contact list related to the selected account item (controller method -> getRelatedContactRecords )

The rerender tag plays a crucial role, since it refreshes the contact list layout every time an account is selected.

Support us with a small donation:

  • LTC Address: La5f6W1rPr5VHFGCrCmPJ3sSa2AiwKZJbU
  • BTC Address: 1FG1j42MUze8jiW7JbgNaUMZxZeu7M1b4f
  • Ripple Address: rPVMhWBsfF9iMXYj3aAzJVkPDTFNSyWdKy     Tag: 562614972
  • ETH Address: 0x0940958167ca9cbd6409999957a011be7907d904
(Visited 403 times, 1 visits today)
Francesco Boccassi
Francesco Boccassi

Francesco is what the business chemistry calls a blend between a Pioneer, always looking for the next generation idea, and a Driver, methodical and clear goal minded. With more than 6 years in consulting he has a deep knowledge of CRM and Salesforce. He is now focusing on Blockchain and DApps.

Leave a Comment