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
mikeolmikeol 

Limit SF Data Connector to "count" records

Is there a way, particularly for testing, to limit the number of records returned by a query to the first "n" records (as well as the normal filtering such as field equals xxx)?

Many thanks.
Ron HessRon Hess
No method built in, however it would be a very few lines of code to break out of the query draw loop after one "batch" , and the batch size is a variable configurable in the code.
foghornfoghorn
Best way without a lot of overhead to get the size of a result set

session.SetSoapHeader "QueryOptions", "batchSize", "1"

set qr = session.Query("select id from account",False)

'no need to look at any of the results

MsgBox qr.Size

'Be sure to set the batchSize back again after you finish

session.SetSoapHeader "QueryOptions", "batchSize", "2000"
mikeolmikeol
Hi,

Pardon my ignorance but where in SF Data Connector do I put the code suggested?:
session.SetSoapHeader "QueryOptions", "batchSize", "1"
set qr = session.Query("select id from account",False)
'no need to look at any of the results
MsgBox qr.Size
'Be sure to set the batchSize back again after you finish
session.SetSoapHeader "QueryOptions", "batchSize", "2000"
Ron HessRon Hess
when you run a normal query, the app status bar shows progress by displaying

drawing row 23 of 322

or something, so you can see that this "count" or qr.size is fetched and displyed already.

search for :
Set queryData = salesforce.query("select id from " & g_objectType & " " & where)

in the query_draw() function, in module s_force

then you can get the "count" by inserting
msgbox queryData.size

strictly speaking you dont' need to set the batch size, that is a performance optimization.
mikeolmikeol
queryData.size tells me how many records match the criteria which for example may be 90.

I want to be able to set a universal numeric limit on top of the filter, e.g. 10 (effectively show me up to 10 of the records that match the filter). queryData.size is read only. What do I set to stop the retrieval and display process?

Thanks.
Ron HessRon Hess
inside the query_draw() function , in s_force module, you could break out of the loop

search for :

For Each ids In queryData
idlist(cnt) = ids.Item("Id").value
cnt = cnt + 1

[...blah, blah]
Next ids


---------

add one line after the cnt increment, to exit this For loop when you hit your number

if (cnt > 10) Then Exit For


i havent' tested this, but this is the code that draws the results row by row.