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
Rafael.Martins.SantosRafael.Martins.Santos 

Display a List on a table in visualforce

Hi,

I need fill some columns with the value of the same field, but until now I can't make this work. So I wondering if I can use a variable of type list to get all the informations that I need and display in a table that each value will be separated by <tr><td>VALUE[0]</td></tr>
is it possible?

Best Regards
Rafael
AnupamAnupam
You can create a wrapper class and build your data accordingly and accumulate it in a list. Use the same list on the VF page.
AnupamAnupam
Hi

I do not have any code, i am just giving solution. For more info please visit link : https://developer.salesforce.com/page/Wrapper_Class 
Rafael.Martins.SantosRafael.Martins.Santos
Hi, 
Yes I will share the code with you.

First I will explain what I need.
  • In the first column of the image above, I have a list with account names
  • In the Column 2, 3, 4 and 5, I have the products of each especific account.
  • So, I must display in each cell the STATUS of the especific product and account.


User-added image

Object Account - Account
Object Produto_da_Mancha__c - Suporte, ADM, BS/BH, ServiceNow

Each Product have a field Called Status__c, and each product is a Register (The registers are generated automatically by trigger).

Here is my Code

VisualForce:

<apex:page showHeader="false" sidebar="false" standardStylesheets="false"
applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" controller="Account_Mancha">
<html>
<head>
    <title>Mancha</title>
</head>
<body>
    <header>
        <div class="bar_container">
            <ul>
            <li>
                <a href="">Oportunidade</a>
            </li>
            <li>
                <a href="">Contas</a>
            </li>
            <li>
                <a href="">Contatos</a>
            </li>
        </ul>
        </div>
    </header>
    <div class="painel">
        <h1>MANCHA</h1>
        <table>
            <tr>
                <th colspan="1" class="celula_em_branco"></th>
                <th colspan="4" class="celula_azul_escuro">MANAGED SERVICES</th>
            </tr>
            <tr>
                <td class="cor_cinza td_column">Account</td>
                <td class="cor_cinza td_column">Suporte</td>
                <td class="cor_cinza td_column">Adm</td>
                <td class="cor_cinza td_column">BS/BH</td>
                <td class="cor_cinza td_column">ServiceNow</td>
            </tr>
            <apex:repeat value="{!TodasContas}" var="conta">
           <tr>
            <td class="celula_azul_escuro">{!conta.Name}</td>
            <apex:repeat value="{!conta.Produtos_da_Mancha__r}" var="produtos">
            <td class="cor_azul">{!produtos.Status__c}</td>
            <td class="cor_verde">HERE MUST ADM STATUS}</td>
            <td class="cor_amarelo">HERE MUST BS/BH STATUS</td>
            <td class="cor_azul">HERE MUST BE SERVICENOW STATUS</td>
            </apex:repeat>
            </tr>
          </apex:repeat>

        </table>
    </div>
    <footer>
        <div class="bar_container">
            <ul>
                <li>SERVICE IT</li>
            </ul>
        </div>
    </footer>
</body>
</html>
</apex:page>


APEX:
public class Account_Mancha {
    
      public Account_Mancha(){
          
      }
    
    public List<Account> getTodasContas(){
        List<Account> accounts = [SELECT Account.Id, Account.Name, (SELECT Produto_da_Mancha__c.Name, Produto_da_Mancha__c.Conta_Id__c, Produto_da_Mancha__c.Status__c FROM Produtos_da_Mancha__r WHERE Produto_da_Mancha__c.Conta_Id__c != null AND Produto_da_Mancha__c.Name = 'Suporte') FROM Account];

       return accounts;
    }

}



Best Regards

Rafael
Rafael.Martins.SantosRafael.Martins.Santos
Hi,
Any help about this issue?
 
AnupamAnupam
Hi
Create a wrapper class as below

Class accoutProdWrapper{
String AccountName;
Map<String, String> Product2Status; //hold key value pair of product and their status
}

Create list of wrapper class i.e List<accountProdWrapper> and add records to it doing respective queries.

User this list on the VF page to display values in the table.

Hope this helps !