Skip to main content

I have a mass action that updates rows on a table.  The table might have 20 rows, or many more - 70 or 80.  If I try to update a larger number (say, 70), I get an error: “Unable to gain exclusive access to rows.”  Is there a way to batch up this action so that the update happens in smaller chunks?  

You can setup a loop between a global action and  an action sequence. Set the model to max 20 records. The global action calls the sequence. The sequence checks that {{$Model.MODELNAMEHERE.data.length}} > 0. If yes then do your actions and call itself at the end. You could get fancy by creating another agg model so you can show the number of records left to go in a message. {{$Model.AGGMODELNAMEHERE.data.length}}


Clever!!  I will try this out.  Thanks so much.


Pat, I don’t think this is going to work.  I need to show all the models in my original table so that users can select just a few if they want to.  I am merging the selected records into a “temporary” model and then performing the update on that model, using a snippet.  (I’m actually creating child rows on the selected records as well as updating a field on the record - hence the snippet.) I thought that my temporary model might actually help me - I could set a record limit on that model and then use your suggestion to create a loop - but the record limit isn’t respected when I adopt rows into the temporary model.  

So - I’m wondering if there’s a way in my snippet to specify how many rows I want to update.  Then, I could follow the logic of global action/action sequence loop.


Definitely can do this. Better to just GTM sometime to power through it together. Saturday or Sunday?


Pat, that would be amazing.  I’ll send you a note on LinkedIn!


I’ve done some troubleshooting to see if I can turn off other automation in the system and get this to run… but no luck!  Trying some javascript to batch this up, but I can’t figure out how to update just a subset of records.  Here’s what I have: 


var models = skuid.model.map();

var Cases = models.CasesToCover;


    var records = skuid.$.map(argumentsm0].list.getSelectedItems(),function(item){ 

        return item.row.Id; 

    });


var n = 0,

    max = records.length;

    batch = 10;


(function nextBatch() {

    for (var i = 0; i < batch && n < max; ++i, ++n) {

        

        Cases.save();


    }

    if (n < max) {

        setTimeout(nextBatch, 0);

    }

})();


Hmmm … can you provide a screenshot of the objects in use in schema builder? And a example of which records are getting updated with which value(s).


Pat, nothing is getting updated - we get the Apex CPU time limit error, which I assume means that this Javascript is trying to update every record in the Cases model rather than the batch of 10.  The only object here is the standard Case.  
(In my mass action, there’s a field update that precedes this snippet.)  
I deactivated all my Process Builder rules without any affect.  I assume there’s still something else going on… but hoping for a Javascript quick-fix if there is one.


Is it possible that 2 updates are for the same record?


not sure.  I don’t think so… but I’m not sure how to figure that out.  I’ve tried moving the field update and save to my snippet, but the following isn’t working at all - after seeing the records logged in the console, nothing hapens - no errors or anything. 


var models = skuid.model.map();

var Cases = models.CasesToCover;


    var records = skuid.$.map(arguments$0].list.getSelectedItems(),function(item){ 

        return item.row.Id; 

    });


console.log(records);


var n = 0,

    max = records.length;

    batch = 10;


(function nextBatch() {

    for (var i = 0; i < batch && n < max; ++i, ++n) {

        

        Cases.updateRow(records, {

            ‘Case_Team_Updated__c’ : skuid.time.getSFDateTime(new Date()) } );

        Cases.save();

    }

    

  if (n < max) {

        setTimeout(nextBatch, 0);

    }

  

});


GTM today or tomorrow?


Reply