You need to sign in to do that
Don't have an account?
wsmith
Is there a best practice for allowing a web service to return more then 1000 objects?
Apex arrays have a Governor limit of 1000 elements. If I have a web service that returns an array of objects, is there a best practice for allowing a web service to return more then 1000 objects/ Perhaps a query more type API where the array returns objects in a range specified by the user.
Is there a best practice for allowing a web service to return more then 1000 objects?
Is there a best practice for allowing a web service to return more then 1000 objects?
but you can process those 1000 records then get another batch.
is the service you are consuming flexible in how many records you can request?
Obj[] getObj(Integer startIndex, Integer numberOfObjects); where numberOfObjects has a maximum of 1000.
However this leaves the questions of how do I sort the result set for the best results (by Name, Salesforce Id, Created date, etc.) and most importantly, what happens if the result set changes (by a record update, delete or insert) between web service calls?
Remember that a web service call is stateless and there is ao built in way to save the state or the full result set of the query between web service "query more" calls.
In the case when a record is inserted or deleted, I am concerned the user will either miss a record, when the user asks for the next batch or records, or get a duplicate record in the latter case.
One thought is to look at a "modifiedsince" timestamp in the Object's table but I don't believe the Describe Object (metadata) information contains this information. If the table is modified based on a timestamp parameter, I can invalidate the query and tell the user to restart the query.
Is this a good way to approach the problem?
Hello Ron,
I have a question in the same regard for you.
What exactly does the webservice needs to have, to be able to process records in batches of 10,000?
I am currently facing this problem as my results are way above 10,000 in numbers which leads to exception. Would be obliged if you can throw some light on this.
Thank You,
Cool_D
Our strategy is to return lists of lists of objects. Theoretically this allows a return set of up to 1,000,000 records, but practically you hit the 1 MB heap size governor limit long before that.
In the event where an iterative approach can't be avoided, we do a paged approach, limiting the result set to some maximum size (1,000 recs is convenient) and including a new field in the results to tell the caller where we left off. This field is passed back into the same WebService method in subsequent calls, telling the method where to pick things up.
Clearly, sorting is required at some point - on the field being passed back + forth, as well as a conditional on the underlying field in the SOQL query sitting in the WebService method. What field this is, is an implementation-specific decision. You'd naturally think that the Id field would be the ideal candidate, as it's unique and ubiquitous, but unfortunately the following SOQL is illegal:
[ select Name from Object where Id > :startId order by Id limit 1000 ]
So you have to order by some other field, unfortunately. (Anybody know why you can't do compare ops on the Id field in a SOQL where clause?)
Thanks a ton Phil for your splendid reply. That was very useful indeed.
Unfortunately, i still have one more issue. I have 4 SOQL queries inside my webservice method. So, when my code is executed, all of these queries are included in the context. The overall cumulative count thus goes beyond 10,000 giving me an exception within the code itself that number of records fetched is 10,001.
This basically means that within my code also i need to do batching. Am i correct here?
Is there a way to handle such kind of a scenario? Looking forward to you reply.
Thanks
I hope that makes sense. How exactly you would go about implementing this - is entirely dependent on the details of your method.
Remember, that 10,000-record limit is on a call-by-call basis. Each invocation of your WebSvc method gets a brand new 10,000 records to play with.
I have similar issue.
I have webservice program to return data from 2-3 objects. I implemented this using LIMIT and OFFSET to give user an option to query different set of records. When I ran test query in developer console with LIMIT 400 and OFFSET 0, it works fine.
But when I run this webservice using SOAPUI, it returns only 200 records. Any idea?
Thanks
Hari