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
MarkL.ax269MarkL.ax269 

dynamic field name in Apex

I'm building my own rule processor and I need access to field values where the field in question varies.  In other words, I need something similar to the ajax syntax for returning field values:

String currentValue = oli[fname];
String currentValue = oli.get(fname);

Does anything like this work in apex?  Both the above fail.  Thanks.

Mark
TehNrdTehNrd
Try

oli.name
MarkL.ax269MarkL.ax269
The name of the field is unknown until runtime, hence my question.
TehNrdTehNrd
Whoops, read that too fast.

Not currently possible with Apex. All values must be known and hard coded at runtime. Rumor has it next version of apex will support this but there is no ETA.

http://ideas.salesforce.com/article/show/83292/Enable_Apex_Code_SOQL_queries_of_fields_not_known_at_compile_time

MarkL.ax269MarkL.ax269
Thanks, that's the answere I needed...well maybe not what I needed, but it's the answer.  Thanks for the link too, I just promoted it.  Would be hugely beneficial.

Mark