You need to sign in to do that
Don't have an account?
Sunny Mohla
Pick field names from custom setting
I have a custom setting which saves three field names of lets say contact object. I want to update value of all those fields to null which are store in my custom setting. following is the code that i'm writing.
List<Field_Name__c> mycustomsetting = Field_Name__c.getAll().values();
system.debug('List of custom setting' + mycustomsetting.size());
List<contact> mycontacts = [select id, name,birthdate, Languages__c, Level__c from contact];
string fieldname = '';
for(contact Con : mycontacts)
{
for(integer i=0; i<mycustomsetting.size();i++)
{
system.debug(i+ ' :custom setting : ' + mycustomsetting[i].Field__c);
fieldname = mycustomsetting[i].Field__c;
Con. + fieldname = null; - This is what i'm trying to do but it does not works
Con.birthdate = null; -- This is what needs to be done via custom setting
}
update Con;
}
I have created custom setting as "Field_Name__c" and this contains field as "Field__c" which contains contact field API names.
Any help will be appreciated
List<Field_Name__c> mycustomsetting = Field_Name__c.getAll().values();
system.debug('List of custom setting' + mycustomsetting.size());
List<contact> mycontacts = [select id, name,birthdate, Languages__c, Level__c from contact];
string fieldname = '';
for(contact Con : mycontacts)
{
for(integer i=0; i<mycustomsetting.size();i++)
{
system.debug(i+ ' :custom setting : ' + mycustomsetting[i].Field__c);
fieldname = mycustomsetting[i].Field__c;
Con. + fieldname = null; - This is what i'm trying to do but it does not works
Con.birthdate = null; -- This is what needs to be done via custom setting
}
update Con;
}
I have created custom setting as "Field_Name__c" and this contains field as "Field__c" which contains contact field API names.
Any help will be appreciated
Con.put(fieldname, null);
All Answers
Con.put(fieldname, null);
This does seems to work in developer console. Will apply in my batch class as well.