Skip to content

Instantly share code, notes, and snippets.

@amphro
Created December 11, 2013 18:26
Show Gist options
  • Save amphro/7915765 to your computer and use it in GitHub Desktop.
Save amphro/7915765 to your computer and use it in GitHub Desktop.
Delete ApexLogs where the LogUser returns null, causing a JS error. Run this in the browsers javascript console when on the Developer Console
SfdcDevConsole.ToolingAPI.query('SELECT Id, LogUserId, LogUser.Name FROM ApexLog', {
continuation : function(response) {
var records = response.records;
console.log('Found ' + records.length + ' log(s)');
var idsToDelete = [];
for (var i = 0; i < records.length; i++) {
var rec = records[i];
console.log('\t' + rec.Id + ' ' + rec.LogUserId);
if (!rec.LogUser || rec.LogUser === 'null') {
idsToDelete.push(rec.Id);
}
}
function removeLog(i, logId) {
//Stagger so we don't send all the request at once.
setTimeout(function() {
console.log('\tDeleting log ' + logId);
SfdcDevConsole.ToolingAPI.DELETE('ApexLog', logId, {});
}, 500*i);
}
console.log('Deleting ' + idsToDelete.length + ' log(s)');
//Should probably use bulk api. O-well... just delete one at a time
for (i = 0; i < idsToDelete.length; i++) {
removeLog(i, idsToDelete[i]);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment