+ Start a Discussion
shra1_devshra1_dev 

working with Lists

hi,

 

I am new to salesforce. please help me out in this ..

 

how to get field values into a list and and display it into a visualforce page?

 

thanks,

-shravan

Best Answer chosen by Admin (Salesforce Developers) 
rmehrmeh

Hi,

 

Follow the procedure below to get field values in a list and displaying them in the visualforce page:

  • Declare a List. Say the List is of Account object. So declare it as List<Account> lstAcc = new List<Account>();
  • Query the fields you would like to retrieve and show in your visualforce page. For ex:

       lstAcc = [Select Id, Name, Industry From Account where Id=: put your account Id here limit 1000];

  • Now from here there are two ways you can display values in your VisualForce page:
  • First: If you are standard controller in your page, you can simply do it by setting the property as {!Account.Name}
  • Second: If you are simply using a custom controller, you need to declare a property in your apex controller, say i want to display Account Name.

    Then in the class,

    public String accName{get;set;}               // decalaration of property

   

  • The place where you have queried your list, iterate it in the for loop in there are more than 1 record and then set it to the declared property

       if(!lstAcc.isEmpty())

        {

             for(Account acc: lstAcc)

             {

                   if(acc.Name != null && acc.Name != '')

                   {

                          accName = acc.Name;

                   }

             }

        }

 

Hope this is what you were looking for.

 

All Answers

rmehrmeh

Hi,

 

Follow the procedure below to get field values in a list and displaying them in the visualforce page:

  • Declare a List. Say the List is of Account object. So declare it as List<Account> lstAcc = new List<Account>();
  • Query the fields you would like to retrieve and show in your visualforce page. For ex:

       lstAcc = [Select Id, Name, Industry From Account where Id=: put your account Id here limit 1000];

  • Now from here there are two ways you can display values in your VisualForce page:
  • First: If you are standard controller in your page, you can simply do it by setting the property as {!Account.Name}
  • Second: If you are simply using a custom controller, you need to declare a property in your apex controller, say i want to display Account Name.

    Then in the class,

    public String accName{get;set;}               // decalaration of property

   

  • The place where you have queried your list, iterate it in the for loop in there are more than 1 record and then set it to the declared property

       if(!lstAcc.isEmpty())

        {

             for(Account acc: lstAcc)

             {

                   if(acc.Name != null && acc.Name != '')

                   {

                          accName = acc.Name;

                   }

             }

        }

 

Hope this is what you were looking for.

 

This was selected as the best answer
shra1_devshra1_dev

thanks a lot for clear explanatio about lists.

 

thanks rmeh