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

Why does my query select ALL fields?

OK, this is driving me crazy!  Maybe I'm doing something stupid but please help if you can.
No matter what I do with my query string, it ALWAYS returns ALL the fields.  I thought the 'where' clause was going to be the challenge!
I'm running the following query:
Set qr = ThisWorkbook.cSFComm.Query("Select CreatedByID, CreatedDate, FirstName, Id From Contact", False)
I then loop through this code:

For Each s In qr
    For x = 1 To 25
         MsgBox s.Fields(x).Name
    Next x
Next s
And can frustratingly watch it show me each and every field name from the table!

All the fields are “available” in a sobject, even though you only select a subset. 


If you only want fields with value you can null check the field.Value.


Thank you for the quick response.  I'm happy this forum is being monitored.

So if I understand correctly then, the select portion of the query statement is not fully functional???  If I wanted to query the contact object to obtain the first and last name of the contacts at account "XYZ company", I could not get just the first and last name fields.?.  My app needs to filter out all the extraneous fields?

If that's the case, I can deal with it but it seems to be an awful lot of unused data going back and forth.



You actually only get data for the fields you request (likewise the toolkit only sends data back that has been modified).


The “unused” fields are there for reference as well has being fully functional, e.g. you can set values.

That makes sense.  I will take a closer look at the data returned.  Thanks for your help.
I see.  Is there any way to access the fields with data directly?  Since the query set returns all fields whether or not they actually have needed data, I am scanning each field to see if it matches one that I want and then plucking the data.  This is terribly time consuming with large results (say 1000 records returned from a table that has 40 fields in it).  Since I know which fields I'm looking for, can I access it directly?
Yes, you can access fields by index or by api name.  Check the item collection on the sobject
I am wondering if we can use * to fetch all the fields and their records just like a SQL query "Select * from Table", is that possible ?
another thing which is bothering me is that, i want to develop my own screen for editing a task, how would i get all the task fields so that if there is any new field added in the Task object , it should also be displayed in my own Task screen? also is there any way to populate combo without getting into javascript loop ?
Irfan Shahid.