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
zachzach 

Is there or will there be a retrieveMore() function?

Just wondering... I have a script where I get records tied to a specific account & retrieve would work way quicker than querying, but there are more than 2000 records.

Here's a snippet where it works (though not ideally):

Code:
function buildLinkedArray() {
 for (var a = 0; a < linkedAcctIdArray.length; a++) {
  var info = sforceClient.retrieve("Id,Name,Site,MasterNumber__c,ShipToNumber__c","Account",linkedAcctIdArray[a]);
  window.status = "Returning record "+(a+1)+" of "+linkedAcctIdArray.length;
  linkedAcctArray[a] = new Array();
  linkedAcctArray[a][0] = info[0].get("Id");
  linkedAcctArray[a][1] = info[0].get("Name");
  linkedAcctArray[a][2] = info[0].get("Site");
  linkedAcctArray[a][3] = info[0].get("MasterNumber__c");
  linkedAcctArray[a][4] = info[0].get("ShipToNumber__c");
 }
}

 Here's how I'd like it to work, but linkedAcctIdArray is about 2100 records, so it doesn't:

Code:
function buildLinkedArray() {
 var info = sforceClient.retrieve("Id,Name,Site,MasterNumber__c,ShipToNumber__c","Account",linkedAcctIdArray);
 for (var a = 0; a < info.size; a++) {
  window.status = "Returning record "+(a+1)+" of "+info.size;
  linkedAcctArray[a] = new Array();
  linkedAcctArray[a][0] = info[a].get("Id");
  linkedAcctArray[a][1] = info[a].get("Name");
  linkedAcctArray[a][2] = info[a].get("Site");
  linkedAcctArray[a][3] = info[a].get("MasterNumber__c");
  linkedAcctArray[a][4] = info[a].get("ShipToNumber__c");
 }
}

 

DevAngelDevAngel

There is no need for a retrieveMore function. The code below takes your 2100 id array and creates a new array that will actually only contain 3 elements (but will work for an arbitrary number of inbound ids) and puts 1000 ids in each element.

Then, passing this new array to your buildLinkedArray function, we can loop the first dimension and retrieve 1000 accounts and using the final array as a stack, push the object into the outbound array. Since your code has all the ids up front, you can slice and dice the array how ever you see fit.

Code:

function retrieveStuff(linkedAcctIdArray) {

    var arrayCount = 0;
    //Create some arrays that contain 1000 ids
    for (var i=0;i<linkedAcctIdArray.length;i++) {
        if ((i % 1000) == 0) {
            arrayCount++;
            twoDAccountIdArray[arrayCount] = new Array();
        }
        twoDAccountIdArray[arrayCount].push(linkedAcctIdArray[i]);
    }
    
    function buildLinkedArray(twoDAcctIdArray) {
        linkedAcctArray = new Array();
        for (var i = 0; i < twoDAccountIdArray.length; i++) {
            var info = sforceClient.retrieve("Id,Name,Site,MasterNumber__c,ShipToNumber__c","Account",twoDAcctIdArray[i]);
            for (var a = 0; a < info.size; a++) {
                window.status = "Returning record "+(a+1)+" of "+info.size;
                var oneAccount = new Array();
                oneAccount.push(info[a].get("Id"));
                oneAccount.push(info[a].get("Name"));
                oneAccount.push(info[a].get("Site"));
                oneAccount.push(info[a].get("MasterNumber__c"));
                oneAccount.push(info[a].get("ShipToNumber__c"));
                linkedAcctArray.push(oneAccount);
            }
        }
        return linkedAcctArray;
    }
    
    return buildLinkedArray(twoDAccountIdArray);
}

 

zachzach
Awesome, thanks for the tip!
-Zach
zachzach
Thought I'd make another comment using this logic for retrieve...

It seems that Internet Explorer cycles through big loops quite a bit more slowly than small loops.  So, if you set the batch size to retrieve to be smaller (I usually set it to 50), it will retrieve and loop through the results more quickly than if you have bigger lumps of 500, 1000, or even 2000 records.

I haven't noticed a difference in Firefox, but it definitely makes a difference in IE.

-Zach