You need to sign in to do that
Don't have an account?
Filikin
How to access a field dynamically, given its name
I have a list of fields obtained using a fieldset.
I want to set a value on these fields, but I can't figure out the syntax in Apex.
For example, the email field in the contact object.
Is there a way to preform this operation:
contact.email = 'me@somewhere.com'
if the token 'email' is in a string?
thanks
ok, figured it out using put
contact.put('email', 'me@somewhere.com') seems to do the job
All Answers
ok, figured it out using put
contact.put('email', 'me@somewhere.com') seems to do the job
Yes, you should do it like that.
Also,
sobject.get('fieldName');
gives you the current field value
thanks, good to have confirmation