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
Meiriando Teja Artanta SembiringMeiriando Teja Artanta Sembiring 

APEX:REPEATED VALUE BASED ON VALUE ON SOME RECORD

Hi,

i have some unique requirement now. i have to make report that show like this table below.(i changed the theme to pokemon to make easily understanding).
Pokemon NamePokemon LocationElement Lightning DefenceElement Fire DefenceElement Water DefenceElement Earth Defence
BulbasaurForest0010050
PikachuGrass5000100
CharizardMountain0501000
LaprasSea0100500

i have 3 List =
1. list a<Master_Element>
2. List b<Pokemon_Name>
3. List c<Defence_Atrribute_Each_Pokemon>

the requirement are :
1. not hardcode for the element.if someone add master element, automatically the report will show the new element with the attribute. dont have to change the Visualforce Page.

for the table header i already succesfull make like this below.
<table>
<thead>
<tr>
                    <td align="Center"> Pokemon Name </td>
                    <td align="Center"> Pokemon Location </td>
                        <apex:repeat value="{!Element}" var="e"> 
                        <td align="center">{!e.Element_Name__c}</td>
                        </apex:repeat>
</tr>
</thead>
<tbody>
<apex:repeat value="{!Pokemon}" var="f">
                    <tr>
                        <td>{!f.Pokemon_Name__c}</td>
                        <td>{!f.Pokemon_Location__c}</td>
                         <apex:repeat value="{!DefElementValue}" var="g"> 
                        	<td  align="center">{!g.Def_Pokemon_Element__c}</td>
                        </apex:repeat>
                      <tr>
</apex:repeat>
</tbody>
</table>

my question are:
1. me stuck on show up the def element (remember that the value will follow how many master element exist automatically)
2. Is there any other idea to solve this requirement?maybe like {!defElementValue} get the pokemon name first (filter the list based on what pokemon on that row)

me really desperate for this one, deadline already close anyway. T_T
thank you guys.


TJ
SonamSonam (Salesforce Developers) 
Hi TJ,

For this, I am assuming there is a Pokemon Master object and Defence_Atrribute_Each_Pokemon__c child object 

You can create the map of Pokemon and wrapper of pokemon , Defence_Atrribute_Each_Pokemon__c object.

Class Logic -: 

Map<string,Defence_Atrribute_Each_Pokemon__c> pokemonMap{get;set;} { pokemonMap = new Map<string,Defence_Atrribute_Each_Pokemon__c>(); }


for(Pokemon__c pokemon : [select name__c, location__c , (select lightnig_Defence__c,Firing_defence__c, water_defence__c from Defence_Atrribute_Each_Pokemons__r limit 1) from Pokemon__c]){
    for(Defence_Atrribute_Each_Pokemon__c defenceElemnt : pokemon.Defence_Atrribute_Each_Pokemons__r) {

        pokemonMap.put(pokemon.name__c,new pokemonWrapper(pokemon,defenceElemnt));
    
    }
    
}

Wrapper class logic

public class pokemonWrapper {

  public pokemon__c pok {get;set;}
  public Defence_Atrribute_Each_Pokemon__c DefElemnt {get;set;}
  
  public pokemonWrapper(pokemon__c pok ,Defence_Atrribute_Each_Pokemon__c DefElemnt) {
      this.pok = pok;
      this.DefElemnt = DefElemnt;
  }

}


on Page you can show it like 


<apex:repeat value="{!pokemonMap}" var="f">

<tr>
    <td>{!f}</td>
    <td>{!pokemonMap[f].pok.location__c}</td>
    <td  align="center">{!pokemonMap[f].DefElemnt.lightnig_Defence__c}</td>
    <td  align="center">{!pokemonMap[f].DefElemnt.Firing_defence__c}</td>
    <td  align="center">{!pokemonMap[f].DefElemnt.Water_Defence__c}</td>
    <td  align="center">{!pokemonMap[f].DefElemnt.Earth_defence__c}</td>
  <tr>
    
    </apex:repeat>


Please post the entire code and datamodel of all 3 objects, in case this code doesn't help you in updating your code to work.