Skip to content

Instantly share code, notes, and snippets.

@402332509
Created July 28, 2021 07:18
Show Gist options
  • Save 402332509/1eae3f21a0cba33813d04b50ab46f161 to your computer and use it in GitHub Desktop.
Save 402332509/1eae3f21a0cba33813d04b50ab46f161 to your computer and use it in GitHub Desktop.
import {
login,
queryGenerator,
deleleSobject,
query,
executeAnonymous,
} from "@common/promisify-js-force";
import { chunk } from "lodash";
export const main_handler = async (event, context, callback) => {
await login();
const sumResult = await query(`select sum(LogLength) totalLength from ApexLog`);
let total = sumResult.records[0].totalLength;
const threshold = 700 * 1024 * 1024;
console.log(total);
if (total < threshold) {
return;
}
for await (const { records } of queryGenerator(` select Id, LogLength from ApexLog `)) {
for (const logChunk of chunk(records, 50)) {
await deleleSobject(
"ApexLog",
logChunk.map((log) => log.Id)
);
total -= logChunk.reduce((acc, log) => acc + log.LogLength, 0);
console.log(total);
}
if (total < threshold) {
break;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment