You need to sign in to do that
Don't have an account?
SalesForce Dummy
Access field name value based on string
This may be a simple yes or no question. I'm trying to update a field based on a string. Example.
//Create contact to update and set string to the email field.
Contact TestContact = new Contact(Id = '003121212121212');
string conField = 'Email';
//Update contact email field.
testContact.conField = 'test@email.com';
update testContact;
What I'm trying to do is access a field name for an object based on a string. Is this possible at all in APEX?
You would do something like this maybe:
You may have to make the conEmail string all lowercase. Sometime a Map key allows for non-case sensitive as in the case of field names but I do not recall the exception off hand. So if using conEmail does not work try conEmail.toLowerCase()
All Answers
You would do something like this maybe:
You may have to make the conEmail string all lowercase. Sometime a Map key allows for non-case sensitive as in the case of field names but I do not recall the exception off hand. So if using conEmail does not work try conEmail.toLowerCase()
SObject.get and SObject.set is case-insensitive, and automatically applies the namespace of the managed package it is called from, if any. Other than that, Starz is indeed correct.
Worked like a charm. Thanks a bunch!!!
I'll keep that in mind. Thanks, sfdcfox.