function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
richfer_rightrichfer_right 

how to retrive fieldname from object then get value from that fieldname value from some other object

Hi

I am storing object field name in other object

 

EX

  objeContainer - objects store name, start_c.  name means calendar name , strats_c store startingDate. 

 

first

 

 i need to get field name 

then 

from the field name i need to get value from other object 

 

i am getting field name by the following query 

 

thisEvent =SELECT Id, Name, start__c from myCalendar__c Limit 4

 

here after i need to get values from other object 

 

here i am getting problem . how to query fieldname and get their appropriate values

i am getting error when i query like this 

like this 

 

select  thisEvent.Id,thisEvent.Name,thisEvent.start__c

 

 i got strucked in this stage how to proceed further .

 

Suggestions and examples are welcome 

Thanks in advance

 

 

 

   

Best Answer chosen by Admin (Salesforce Developers) 
mbhardwajmbhardwaj
you can assign the result to a generic sObject list. Then assign the individual records using run time typing.

All Answers

Rahul_sgRahul_sg
i didnt understand the actual business requirement but you should look @ dynamic apex.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describe_objects_understanding.htm
mbhardwajmbhardwaj
Try this::

thisEvent =SELECT Id, Name, start__c from myCalendar__c Limit 4

field1 = thisEvent.Id;
field2 = thisEvent.Name
field3 = thisEvent.objectName;

String qry = 'SELECT ' + field1 + ', ' + field2 +' FROM ' + field3;
List<sObject> rslt = Database.query(qry);
richfer_rightrichfer_right
List<sObject> rslt = Database.query(qry);

here i am getting problem i am actually don't know which kind of object i need to create list -- List<sObject> ?
mbhardwajmbhardwaj
you can assign the result to a generic sObject list. Then assign the individual records using run time typing.
This was selected as the best answer