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
Sachin Patil 57Sachin Patil 57 

How to iterate through 2 lists in a single pageblock table.

Hi all,
I have a task to create a table where i should iterate through 2 lists(dynamic lists). I have used Wrapper class for lists. Below is the code that I have used.
Please someone help me with the code below

*************VisualForce Page**************

<apex:pageBlockSection columns="2"  >
                <apex:pageBlockTable value="{!wrapLists}" var="wrap">
                    <apex:column headerValue="API Names" value= "{!wrap.APINamesList}" />
                    <apex:column headervalue="CSV Fields" value="{!wrap.allCSVFields}" />  
                </apex:pageBlockTable>
            </apex:pageBlockSection> 


*********Controller************

public void getApiNames(){ 	
       wrap = new wrapperClass();
        queryResults = [SELECT API_Names__c,Object__c,Label FROM dataload__mdt WHERE Label= :selectedFunction ];
        allAPINames = queryResults[0].API_Names__c;
        wrap.APINamesList = new List<string>();
        APIList= new List<String>();
        wrapLists.clear();
            for(string APINames: allAPINames.split(',')){
            APINamesMap.put(APINames, APINames);
            system.debug('Test2'+APINames);
            
          wrap.APINamesList.add(APINames);
            System.debug('TEster'+wrap.APINamesList);
              wrapLists.add(wrap);
           // APIList.add(APINames);
        }  
             
    }
    
    Public void saveFile(){
        for(string sac: APIList){
            if(CSVList.contains(sac)){
                insert objDataLoader;
        objAttachment.ParentId = objDataLoader.id;
        insert objAttachment;
            }
        }
        
    }
    
    Public void readcsvFile(){
        CSVList= new List<string>();
        csvFileLines = new List<String>{};
        wrap.allCSVFields= new List<String>();
        wrapLists.clear();
        csvAsString = csvFileBody.toString();
        csvfileLines = csvAsString.split('\n'); 
        for(string st: csvfileLines[0].split(',')){
          wrap.allCSVFields.add(st);
            wrapLists.add(wrap);  
            //CSVList.add(st);  
        }     
    }
    
    public class wrapperClass{
        public List<string> allCSVFields {get;set;}
        public List<String> APINamesList {get; set;}
    }
Lokesh KumarLokesh Kumar
Declare the wrapper variables as a String Here is the example for the same.
https://salesforce.stackexchange.com/questions/103455/how-do-i-display-multiple-list-in-a-table
Sachin Patil 57Sachin Patil 57
Hi Lokesh,
If i declare them as string, How can store all the values into a list. 
I tried by declaring it as string, and I assigned the Wrap.allCSVFields= st; It is showing only the last value of the list.
Lokesh KumarLokesh Kumar
You need to create a list of type wrapper class and add the items into that list
Sachin Patil 57Sachin Patil 57
I have created list of type wrapper class also. And I am adding the List allCSVFields to the wrapperclass list. 
But I am getiing as below when I tried to print in a page block tableUser-added image 
Lokesh KumarLokesh Kumar
Can you paste your code here?
Sachin Patil 57Sachin Patil 57
Should I post the whole controller code?