Backendless Support
 
Answered

Retrive all records in Backendless v4.

I'd like to retrive all the records of a table using "Data Paging".

I've gone through below link but it seems for Backendless v3-

https://backendless.com/feature-17-data-paging-or-how-to-efficiently-load-large-data-sets-in-a-mobile-app/

- not helpful

I've also gone through the docs for Backendless v4 but there is no good example -

https://backendless.com/docs/android/doc.html#data-retrieval-with-paging

Please help me.

Leave a Comment

Comments (2)

photo
1

Hi Ketan,

Sorry we haven't added this examples for the version 4.0 yet

But I have some sample for you:

  1. var APP_ID = '<AppId>';
  2. var API_KEY = '<ApiKey>';
  3. Backendless.initApp(APP_ID, API_KEY);
  4. var table = Backendless.Persistence.of('<TableName>');
  5. var queryBuilder = Backendless.DataQueryBuilder.create();
  6. var allTableData = [];
  7. queryBuilder.setPageSize(100);
  8. retrieveData(queryBuilder)
  9. .then(onSuccess, gotError);
  10. function retrieveData(queryBuilder) {
  11. return table.find(queryBuilder)
  12. .then(result => {
  13. if (result.length) {
  14. allTableData = allTableData.concat(result);
  15. return retrieveNextPage(queryBuilder)
  16. }
  17. })
  18. }
  19. function retrieveNextPage(queryBuilder) {
  20. queryBuilder.prepareNextPage();
  21. return retrieveData(queryBuilder);
  22. }
  23. function onSuccess() {
  24. console.log(allTableData.length);
  25. }
  26. function gotError(err) {
  27. console.log("error message - " + err.message);
  28. console.log("error code - " + err.statusCode);
  29. }

Regards Ilya

photo
1

Hi Ilya Veklenko,

Thanks a lot man, I managed to fetch all records in Backendless v4 api, using above algorithm :D