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
anivesh muppaanivesh muppa 

how to display list of records and its detail page in tabpanel using vf page

i got an issue like i want  to display records of multiple objects in a tabpanel and when i click on record name it should display detail page of respective record.



Thank You in advance , 
NagendraNagendra (Salesforce Developers) 
Hi Anivesh,

Please try the below code. This will display the complete Account details with the related lists. You can modify as its is required.
--VF Code
<apex:page controller="TopAccountController" sidebar="false">
    <apex:sectionHeader title="Top 10 Accounts"/> 
    <apex:dynamicComponent componentValue="{!tabbedView}"/><br/><br/>
</apex:page>


--Controller
public class TopAccountController {
 
    private List<Account> topAccounts;
    public String tabbedView {  set; }
    public TopAccountController (){
        topAccounts = [SELECT Name,AccountNumber,Site,
                AccountSource,AnnualRevenue,
                Industry,Phone,Type FROM Account LIMIT 6]; 
    }
 
    public Component.Apex.TabPanel getTabbedView(){
        Component.Apex.TabPanel panel = new Component.Apex.TabPanel(
                                                       switchType = 'client',
                                                       title = 'Top 10 Accounts');
        String lastAccountId;
    
        for (Integer i = 0; i< topAccounts.size(); i++){
            Account o = topAccounts[i];
            
            if (lastAccountId != o.Id){
                Component.Apex.Tab acctTab = new Component.Apex.Tab();
                acctTab.label = o.Name;
                Component.Apex.detail rl = new Component.Apex.detail();
                system.debug('Before RL');
                rl.subject=o.Id;
                rl.relatedList = TRUE;
                rl.title = false;
                acctTab.childcomponents.add(rl);
                system.debug('After RL');
                panel.childComponents.add(acctTab);

            }   

          /*  Component.Apex.OutputText oppText = new Component.Apex.OutputText(escape = false);
            oppText.value = '';
            
            if (lastAccountId != o.Id){
                oppText.value += '<table class="customT"><thead class="customT"><tr class="customT"><th class="customT">Account Number</th><th class="customT">Company Name</th><th class="customT">Type</th><th class="customT">Industry</th><th class="customT">Phone No.</th><th class="customT">Expected Revenue</th></tr><tBody class="customT"></thead><tBody class="customT">';
            }
 
            oppText.value += '<tr><td class="customT">' + o.AccountNumber + '</td>';
            oppText.value += '<td class="customT">' + o.Type + '</td>';
            oppText.value += '<td class="customT">' + o.Industry + '</td>';
            oppText.value += '<td class="customT">' + o.Phone + '</td>';
            oppText.value += '<td class="customT">' + o.AnnualRevenue + '</td>';
            oppText.value += '</tr>';            
 
            if ( (i == topAccounts.size() -1) || o.Id != topAccounts[i+1].Id ){
                 oppText.value += '</tBody></table>';     
            } 
 
            panel.childComponents.get(panel.childComponents.size() -1 ).childComponents.add(oppText); 
            lastAccountId = o.Id; */
        }
        return panel;
    }

}
Hope this helps.

Please mark this as solved if it's resolved.

Thanks,
Nagendra.
 
anivesh muppaanivesh muppa
hai Nagendra,

     i think this ans shows me a path to work on multiple object as well.

Thanks for ur Answer,