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

how to use string varibale to assign column name while updating records.
Hello,
i have a method updateRecords to update selected records from VF page on button click, below is the code
public PageReference updateRecords()
{
List<StareAndCompare> selRecords = GetSelectedRecords();
Contact updateContact;
String strFieldName;
if(selRecords.size() > 0)
{
updateContact = [SELECT c.FirstName, c.LastName, c.Title, c.Email, c.Phone, c.MailingStreet, c.MailingCity, c.MailingState FROM Contact c WHERE c.Id = :selRecords[0].Id];
for(Integer i=0 ; i<selRecords.size() ; i++)
{
strFieldName = selRecords[i].SFFIeldName;
updateContact.strFieldName = selRecords[i].InfoValue;
}
update updateContact;
}
return null;
}
i need to assign the column Name by using a varibale, and the problem is on lines inside the loop i.e. --
strFieldName = selRecords[i].SFFIeldName;
updateContact.strFieldName = selRecords[i].InfoValue;
need to assign fieldName from List variable "selRecords" to the string varibale and use it as the column name in next line . For eg. if strFiledName = 'FirstName' then on the line
"updateContact.strFieldName = selRecords[i].InfoValue;" the string value is not used, but it treats strFieldName as columnName.
Please help as i'm stuck i this issue.
Thanks in Advance.
Use SObject instead. Here's a quick example I just wrote to show you how to do this:
More information on SObject here:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm?SearchType=Stem&Highlight=sObject|sObjects|SObject|SObjects|sobjects|sobject|Sobject
All Answers
Use SObject instead. Here's a quick example I just wrote to show you how to do this:
More information on SObject here:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm?SearchType=Stem&Highlight=sObject|sObjects|SObject|SObjects|sobjects|sobject|Sobject
Thanks a lot, it worked :)