You need to sign in to do that
Don't have an account?
JJE_OLD
Getting field value dynamically
Hi,
I'm looking for a way to access an object field dynamically (i.e. with the field name contained in a variable)
If I have:
String FieldName = 'AccountNumber'; Account ac = [SELECT id, Name, AccountNumber FROM Account LIMIT 1];
I'm trying to do something like this:
Result = ac[FieldName];
Where Result is the Value contained in the AccountNumber Field.
Is there a way to do this in apex?
thanks.
Hi,
You can use the follow method for retrieving the field values using dynamic apex
SObject s = [SELECT accountNumber FROM account LIMIT 1];
Object o = s.get('AccountNumber');
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.