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
DodiDodi 

Help with getting correct value from a List Object

Dear Gurus,

 

this is probably a no-brainer, but I am looking for help with the following:

 

I have an Apex class where I am trying to access values from a field that I have put in a List object. Then object populates as expected...However the below string format is returned using the method - uanVals.get(i). It is my understaning that the get method on the List object will return me the result in the proper index ....which it does.

 

The method  uanVals.get(i) from  a list object returns the proper records, however the formate below is giving me trouble.

 

"Utility_Account__c:{Utility_Account_Number__c=1008901001900249540108, Id=a0EQ0000001trzXMAQ}"

 

How can I get the call from the list object to only return me the string value I need. In this case '1008901001900249540108';

 

Thanks in advance

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

It seems that you have created the list of objects. This list contains objects as elements. So when you tried to access a element of list( that is an object), it returned an object. In your case if you want to access a particular field of that object then your syntax should be like given below,

(uanVals.get(i)). Utility_Account_Number__c

All Answers

Pradeep_NavatarPradeep_Navatar

It seems that you have created the list of objects. This list contains objects as elements. So when you tried to access a element of list( that is an object), it returned an object. In your case if you want to access a particular field of that object then your syntax should be like given below,

(uanVals.get(i)). Utility_Account_Number__c

This was selected as the best answer
DodiDodi

Thanks Pradeep, your solution works!