You need to sign in to do that
Don't have an account?
Multiman
Find out what fields were returned after executing a SOQL string
I have APEX code that executes a SOQL query dynamically and returns a list of sObject. The SOQL string is only known at runtime (stored in Custom Settings). So I don't know which fields were actually queried.
Now if I want to iterate through the result list and dispaly kind of a table of all values, I would need to know which fields were queried in the SOQL string.
Is there a way to find out what fields are contained in the single sObjects?
Thanks
Alex
You can see the fields queried when you are firing the SOQL query . .. Can you give an example how you are querying ?
Do you mean parse the query string and find out which field were queried? Well parsing a SOQL string can be extremely complicated since you might have to deal with agregate functions, relationship fields or sub-queries.
SELECT Id, Name, Owner.Name, (SELECT Name, Stage FROM Opportunities), Industry FROM Account WHERE Id IN (SELECT Account FROM Contact WHERE Email LIKE '%@salesforce.com') ORDER BY Industry
Try to parse this for which fields were queried :)
But again, the SOQL query can be anything and it is configured by an Admin in the Custom Settings.
I am querying like this
List<sObject> L = Database.query(mySoqlString);
where mySoqlString is taken from the Custom Settings
Sorry .. probably I got your question wrong :
I thought you just want to see the query not the query fields..
System.Debug(mySoqlString );
will show the query....