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

eval like functionality
Hi All,
String field = 'name';
Account acc = [select id,name from account limit 1];
acc.field = 'Jon';
I am running this code. This produces error. I want to have eval(Javascript) like functionaly in Apex. So that I can do something like this eval(acc.field) = 'Jon';
Thanks
You can not bind field like this :
acc.field = 'Jon';
Name after '.' should be an API name of field in an object.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
I think you want to print of view the Name = 'Jon' which you are assigining to Any Account.
If the case is something different, could you please explain some more.
Else for just to see the output, run this code:
Run this in system debug and see the output.
If you are looking to dynamically change which field you are setting, you can do something like this. I added a couple debugs so you can verify the change.
Or if you are just looking to get the value from the field then: