You need to sign in to do that
Don't have an account?
shylaja
Getting field names from query result
Hi all,
From the below query, I want to get the field names provided in the query from the result 'obj' dynamically.
sObject obj =[Select id, Owner, Additional_Info__c, Replacement_Info__c, Phone, Mobile__c,Comments__c from Account where ID =:ID];
Regards,
Shylaja
You doesnt seem to generate the SOQL dynamically and seems like while querying you are aware about the fields which should be present.
To get the field values Dynamically you need to do something like this
sObject.get('FieldApiName');
Thanks for your reply Avi!
Actually we get the query as a parameter for a method, within the method we will execute the query using database.query(QueryString);
Now, we want to get the FieldApiNames from the query result.
Shylaja
Hi
if I am not wrong you want to fetch list of field name on any object. you can do it by applying describe method on object. as below :
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
Here fieldMap.Values() is list of field you can get field name and label as below
for(Schema.SObjectField sfield : fieldMap.Values())
{
system.debug( sfield.getDescribe().getLabel()+'========'+ sfield.getDescribe().getName());
}
I know it too late but check it once.
I think you want to get all the field that is used in soql. Please have a look on below code.
I hope this solution will work for you. Let me know if you have any doubt.