You need to sign in to do that
Don't have an account?
Ralph Sr
How do I dynamically reference a field on an object
My subject line may not properly state what I am trying to do...
Hopefully the short code sample below makes more sense of what I am tryhing to accomplish.
List<Test_Object__c> testObject = new List<Test_Object__c>();
testObject = [SELECT Id, Field1__c, Field2__c FROM TestObject__c]
String FieldNameNeeded = 'Field1__c';
for (Test_Object__c test : testObject) {
FieldValueNeeded = test.Field1__c; //hardcoded field name
}
How to I correctly use the variable FieldNameNeeded instead of hardcoding the fieldname? I could not find a reference using Schema data that made sense...
Hopefully the short code sample below makes more sense of what I am tryhing to accomplish.
List<Test_Object__c> testObject = new List<Test_Object__c>();
testObject = [SELECT Id, Field1__c, Field2__c FROM TestObject__c]
String FieldNameNeeded = 'Field1__c';
for (Test_Object__c test : testObject) {
FieldValueNeeded = test.Field1__c; //hardcoded field name
}
How to I correctly use the variable FieldNameNeeded instead of hardcoding the fieldname? I could not find a reference using Schema data that made sense...
All Answers