Apex Class
public class DeleteInactiveAccountsQueueable implements Queueable {
public void execute(QueueableContext context) {
List<Account> inactiveAccounts = [SELECT Id FROM Account WHERE Active__c = 'No'];
delete inactiveAccounts;
System.debug('Deleted ' + inactiveAccounts.size() + ' inactive accounts');
}
}
Apex Test Class
@IsTest
public class DeleteInactiveAccountsQueueableTest {
@IsTest
static void testDeleteInactiveAccounts() {
List<Account> testAccounts = new List<Account>();
for (Integer i = 0; i < 10; i++) {
Account acc = new Account(Name='Test Account ' + i, Active__c='Yes');
testAccounts.add(acc);
}
insert testAccounts;
testAccounts[2].Active__c = 'No';
testAccounts[4].Active__c = 'No';
testAccounts[6].Active__c = 'No';
update testAccounts;
Test.startTest();
DeleteInactiveAccountsQueueable job = new DeleteInactiveAccountsQueueable();
System.enqueueJob(job);
Test.stopTest();
List<Account> remainingAccounts = [SELECT Id FROM Account];
System.assertEquals(7, remainingAccounts.size(), 'Expected 7 accounts remaining after deleting inactive accounts');
}
}
Video
Video does not exists.