Skip to content

Instantly share code, notes, and snippets.

@surajp
Last active May 11, 2024 03:17
Show Gist options
  • Select an option

  • Save surajp/49efe81514c4ba90421cd9c6b0b82658 to your computer and use it in GitHub Desktop.

Select an option

Save surajp/49efe81514c4ba90421cd9c6b0b82658 to your computer and use it in GitHub Desktop.
Delete Apex Logs
const { exec } = require("child_process");
const orgName = process.argv.slice(2)[0];
if (!orgName) {
console.log(
`usage: node ${__filename.replace(/.*(\/|\\)/, "")} <orgname or alias>`
);
process.exit(1);
}
exec(
`sfdx force:data:soql:query -q "Select Id from ApexLog" -t -u ${orgName} -r csv`,
(err, stdout) => {
if (err) {
console.log(`${err.message}`);
return;
}
let op = `${stdout}`.split("\n");
op.shift();
console.log(op);
op.forEach((logId) => {
if (logId) {
console.log(logId);
exec(
`sfdx force:data:record:delete -s ApexLog -i ${logId} -t -u ${orgName} `,
(deleteError, stdout2) => {
if (deleteError) {
console.log(`Error for ${logId}: ${deleteError.message}`);
process.exit(1);
} else if (stdout2) console.log(`Output for ${logId}: ${stdout2}`);
}
);
}
});
}
);
#!/usr/bin/env bash
cat flow_versions_delete.csv | xargs -P 3 -n 1 -I {} bash -c "sfdx data:record:delete -i {} -s Flow -o my-org -t"
HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
request.setMethod('DELETE');
Http sender = new Http();
for(ApexLog log: [Select Id from ApexLog]){
request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v36.0/tooling/sobjects/ApexLog/'+log.Id+'/');
sender.send(request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment