+ Start a Discussion

Bulk/Mass update using latest AJAX toolkit...

Hey all-
I thought I had done this before but I seem to be banging my head against a wall. I need to do a mass update on a set of accounts (And do not want to do this one via a trigger). So I get all my accounts and then I want to insert them in groups of 190 (I rember reading somwhere that the limit was 200). It feels like a syntax issue. Here is what I have right now:
This is the function that gets the list of Accounts from an Async query. I have reduced it to the most simple logic and cannot even get this to function.
function success(qResult) {

  var accountsReturned = qResult.getArray("records"); 
  var accountsForUpdate = [];
  if(qResult.size > 0) { 

   for (var i=0; i<qResult.size; i++) {
    var curAccount = accountsReturned[i];

            try {
              var result = sforce.connection.update([accountsForUpdate]);
  if (result[0].getBoolean("success") == false) { alert(result[0]);}
  } catch(e) {

 It returns this error:
"{errors:[fields:null, message:'sObject type 'sObject' is not supported. If you are attempting to use a custom object..."
Please o please can someone point me in the right direction or let me know if what I am doing is out of bounds....
Thanks in advance for any help!
Depending on what fields you queried on, you may need to create new instances of each account to update. SF will try to update every field that was selected, including ones that are not updatable (like the sobject type field).

Try something like this inside your loop:
for (var i=0; i<qResult.size; i++) {
var curAccount = accountsReturned[i];
var newAcct = new sforce.SObject("Account");
newAcct.Id = curAccount.Id;
//any other updates here