I want to use a variable string rather than a hard-coded string in my get method.
For example, for every Field in Object A there will be a record in Object B and the record name is the field api name from Object A. I want to reference Object B's name in a Object A dynamic soql query:
String fieldName = objectB.Name
Sobject objectA = Database.query('Select Id From ObjectA__c Where Id = \'' + ObjectB.Object_A_Id__c + '\' Limit 1');
objectB.Number_Field__c = (integer)objectA.get(fieldName);
I don't know if this is possible. I get the error System.TypeException: Invalid conversion from runtime type Id to Integer. Still new to Apex coding.
ObjectB__c
a child object ofObjectA__c
?