+ Start a Discussion
HemnthHemnth 

Cannot display Lists in visualforce Page. Tried alternatives such as sets and maps still no luck

I tried a simpe code to display a list of contacts in vfpage
public class Payment {
public List<Contact> ls{get;set;}
public Set<String> st{get;set;}
public string str{get;set;}


    public Payment(){
    List<Contact> ls = new List<Contact>();
    ls = [select id, name from contact limit 3];
    Set<String> st = new Set<String>();
    st.add('1111111');
    st.add('addad');
    st.add('gxghdy');
    st.add('6366vx');
    str = '123';
    
    }
}

<apex:page controller="Payment">
    {!ls}{!st}{!str}
    <apex:pageBlock >
        <apex:pageBlockTable value="{!ls}" var="a">
            <apex:column value="{!a.name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
User-added image
checked all sharing settings every thing is public
this is my new dev edition signedup today
i had same issue with one signed up this month
is this a bug or an issue with my code

--- I can see contacts in debug logs
 
Thulasi ReddysThulasi Reddys
Hi Hemnth
we have same post related to your requirement, check folloing post 
https://developer.salesforce.com/forums/?id=9060G000000XivqQAC
Thanks, let us know if it will helps you 
mukesh guptamukesh gupta
Hi Hemnth,

your code is perfect but contact list variable was decleared again new in constracter that's was an issue, Please use below code that's was working perfect :--
 
<apex:page controller="Payment">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!ls}" var="a">
            <apex:column value="{!a.name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
 
public class Payment {
public List<Contact> ls{get;set;}
public Set<String> st{get;set;}
public string str{get;set;}


    public Payment(){
        ls = [select id, name from contact limit 3];
        
        /*Set<String> st = new Set<String>();
        st.add('1111111');
        st.add('addad');
        st.add('gxghdy');
        st.add('6366vx');
        str = '123';*/
        
    }
}
Kindly mark my solution as the best answer if it helps you.


Thanks
Mukesh

 
Sandeep YadavSandeep Yadav
Hi
use <apex:form> tag in VF code and don't declare again set of string and List of contact in the constructor
<apex:page controller="Payment">
    {!ls}{!st}{!str}
 <apex:form>
    <apex:pageBlock >
        <apex:pageBlockTable value="{!ls}" var="a">
            <apex:column value="{!a.name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
 </apex:form>
</apex:page>
----------------------------------------------------

public class Payment 
{ 
     public List<Contact> ls{get;set;} 
     public Set<String> st{get;set;} 
     public string str{get;set;} 
  public Payment(){ 
   ls = [select id, name from contact limit 3];
   st = new Set<String>(); 
   st.add('1111111'); 
   st.add('addad'); 
   st.add('gxghdy'); 
   st.add('6366vx'); 
   str = '123'; 
 } 
}
Hope this helps you