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
AkshiiiiiAkshiiiii 

Retrieving one field from a list of fields

I am returning a list of object fields from my apex controller to form a table. Now suppose I  the value of only one of the fields from that list to use somewhere else. How can i do that?
AbhinavAbhinav (Salesforce Developers) 
Hi,

Could you please share the details about list or code snippet and which field you want to retrieve.

Thanks!
Suraj Tripathi 47Suraj Tripathi 47
Hi Akshiiiii,
Greetings!

You can store that value in another list and then you can use that single value.
For example, you want to use the email of Contact.
List<String> emailList = new List<String>();
for(Contact con : [SELECT Email FROM Contact]) {
    emailList.add(con.Email);
}
Now, you can use emailList where you want.

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
surojit Mondalsurojit Mondal
Hi Akshiiiii,

If you are refering list of records in VF page to iterate over, you can refer below code snippet 
 
<apex:repeat var="contact" value="{!contactList}">
 
        <tr>
 
            <td>{!contact.FIELD_API_NAME}</td>
        </tr>
 
</apex:repeat>

Please let me know if it solves your purpose. If not please share where your are trying to access the value of only one of the fields from that list.

Regards,
Surojit
ashnion growerashnion grower
Flying Together Ual Login – Flyingtogether.Ual.com is the united airlines’ employee login official website