Skip to content

Instantly share code, notes, and snippets.

@donners77
donners77 / DeleteRecordsBatchable.cls
Last active November 19, 2023 21:18
Bulk delete records in Salesforce using an Apex batch job
// Example use:
// First edit code below and replace ###ObjectName### with Contact
// Then execute in the Developer Console | Debug | Open Execute Anonymous Window
// DeleteRecordsBatchable batchable = new DeleteRecordsBatchable('SELECT Id FROM Contact WHERE Name = \'DeleteMe\'');
// Id batchId = Database.executeBatch(batchable, 10);
global class DeleteRecordsBatchable implements Database.Batchable<sObject> { // created to bulk delete records - use with care!
// Fields
global final String Query;
var querystrings = new System.Collections.Generic.Dictionary<string, string>();
querystrings.Add("where", "ContactNumber = \"123\"");
querystrings.Add("order", "Name DESC");
IConsumerRequest filteredGetContactRequest = consumerSession
.Request()
.ForMethod("GET")
.WithQueryParameters((IDictionary)querystrings)
.ForUri(new Uri("https://api.xero.com/api.xro/2.0/Contacts"))
.SignWithToken(accessToken);