You need to sign in to do that
Don't have an account?

get value from generic sObject list
Hello community,
I’m having a difficult time trying to access values from a list of generic sObject. Example:
Typically, I would do something like this:
My ultimate goal will be to use a while loop and select the row of the sObject list using an iterating variable. This and many others data points will then be constructed in a wrapped class for charting.
Please help
I’m having a difficult time trying to access values from a list of generic sObject. Example:
Typically, I would do something like this:
list <account> acctlist = [select id, name, phone from account limit 100]; string RocordNum51 = acctlist[50].name;this works fine but I can’t seem get the same result with the following example:
list <sobject> QueryObject = database.query(QueryString); integer intvar = QueryObject[50].TheNumnote that ‘TheNum ’ is the alias from the query string select statement
My ultimate goal will be to use a while loop and select the row of the sObject list using an iterating variable. This and many others data points will then be constructed in a wrapped class for charting.
Please help
All Answers
Please try this
list <sobject> QueryObject = database.query(QueryString);
integer intValue = QueryObject[50].get('TheNum__c');
Where, TheNum__c is the api field name of the custom field you are trying to get in your object.
Please see this article for more detail https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_dml.htm?search_text=dynamic%20apex