I wrote a map reduce script to mass delete records using either a saved search or CSV as input as this comes up a lot. My script work excellent in some accounts that have 20-30 queues and deletes 10k journal entries in a flash. I am running into usage issues when needing to delete large data sets however and would like to know if someone could share insight as to why.
[IMG2=JSON]{"data-align":"none","data-size":"full","height":"248","width":"705","src":"https://files.slack.com/files-pri/T08JT8U5V-F64QJ6EAF/image.png"}[/IMG2]
To my knowledge Map / Reduce goveranance works as specified below
GetInputData -> 10,000 usage
Map -> 1,000 usage per invocation
Reduce -> 5,000 usage per invocation
Sumary -> 10,000 usage
I am getting a "Script Execution Usage Limit Exceeded" despite only deleting 50 records in a reduce stage. In this case I'm deleting only contacts which is like 10/15 units. 750 < 5000 so I'm not sure what is causing the issue. It doesn't appear to be instructions or time limit as those give back different errors.
There is only 1 queue in this particular account so I'm switching to a 1.0 scheduled script as its just as fast anyway for this particular account. Regardless I'd like to know why this is happening.
Here is the code I use
reduce: function(context) { try { var recordsToDelete = JSON.parse(context.values[0]); log.debug({ title: '# Records To Delete', details: recordsToDelete.internalids.length }); deleteRecords(recordsToDelete); } catch (errorObject) { log.error({ title: 'Reduce Error', details: getErrorDetails(errorObject) }); } }, function deleteRecords(recordsToDelete) { try { var recordType = recordsToDelete.type; log.debug({ title: "Purging records", details: recordsToDelete.internalids.length }); for (var i = 0; i &lt; recordsToDelete.internalids.length; i++) { var recordId = recordsToDelete.internalids[i]; record.delete({ type: recordType, id: recordId }); } } catch (errorObject) { log.error({ title: 'Could not delete file', details: recordId + ': ' + getErrorDetails(errorObject) }); } } Here is an example input I have for the reduce stage. I supply a type and then an array of ids of that type [{"type":"contact","internalids":["1945","1946","111730","76444","61979","2297","46211","235750","64633","103246","223155","56535","67966","11459","11989","13531","13883","13699","12961","11588","13618","12954","13914","13408","12833","11583","159237","12080","11341","11887","12005","12936","13269","13675","11614","12175","11719","159236","11428"]}]