You need to sign in to do that
Don't have an account?
Ken Koellner
Dynamically reference and set sObject fields.
I know how to write dynamic sSoql in Apex where I can control the select list with code.
What I want to do is dynmically set certain fields in an sObject before I save it. I'll have the names of the fields in variables.
Anyone know if there's a way to set a field in an sObject where the field name is set dynamically.
I want to do something like--
mySObject.setField('FieldName', 'NewValue');
I think I might have found the answer. I see that sObject as a put(fieldname,newvalue) and get(fieldname) methods.
Here is the code :
For more info how to work with sObjects please visit :
http://forceguru.blogspot.com/2011/08/inserting-sobject-dynamically-in.html
And for more info on sObject methods :
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm
Thanks
Ankit Arora
Blog | Facebook | Blog Page