• Bnt Soft
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm looking for a way to dynamically bind a string's value, which contains a Field API Name, with an sObject instance variable and set the value of the sobject field to yet another string.  Here is what I mean.

 

Here is what I can do.

 

My_Custom_Object__c cRecord = new My_Custom_Object__c (); 
cRecord.field1__c = 'field value'; 
String X = cRecord.field1__c;

 So String X would be equal to 'field value'.

 

Here is what I'd like to do.

 

My_Custom_Object__c cRecord = new My_Custom_Object__c ();
cRecord.field1__c = 'field value';
String Y = 'field1__c';
String X = cRecord.Y;

 

Clearly the error I get is that the Y field does not exist, so is there a special notation for doing this?  I've seen similar things done in dynamic SOQL, but not in APEX.  http://salesforce.stackexchange.com/questions/8408/bind-variable-with-dotted-name-not-working-in-dynamic-soql.
 
Any ideas?  Is there some method like, value(Y),  for cRecord.value(Y)? Just some method that passes on the value of the string instead of the dot notation looking for a field named 'Y'?
 
Thank you!
 
  • October 10, 2013
  • Like
  • 0