You need to sign in to do that
Don't have an account?
Jyoti Trailhead
Need help in Test Class
Hi
I am new to Apex and created a class to delete Assets from Base Element class of particular status - here is the code : please help me in creating test class for code coverage.
##############################################################
global class BMCRF_ScheduledDeleteAssets Implements Schedulable {
global void execute(SchedulableContext sc) {
massDelete();
}
// Query the accounts to delete
public void massDelete() {
List <BMCServiceDesk__BMC_BaseElement__c> listtoDelete = [Select Id FROM BMCServiceDesk__BMC_BaseElement__c WHERE BMCServiceDesk__CI_Status__c =: 'Disposal'];
// Delete the assets
Database.DeleteResult[] drList = Database.delete(listtoDelete, false);
// Iterate through each returned result
for(Database.DeleteResult dr : drList) {
if (dr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully deleted account with ID: ' + dr.getId());
}
else {
for(Database.Error err : dr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Account fields that affected this error: ' + err.getFields());
}
}
}
#########################################################
}
}
I am new to Apex and created a class to delete Assets from Base Element class of particular status - here is the code : please help me in creating test class for code coverage.
##############################################################
global class BMCRF_ScheduledDeleteAssets Implements Schedulable {
global void execute(SchedulableContext sc) {
massDelete();
}
// Query the accounts to delete
public void massDelete() {
List <BMCServiceDesk__BMC_BaseElement__c> listtoDelete = [Select Id FROM BMCServiceDesk__BMC_BaseElement__c WHERE BMCServiceDesk__CI_Status__c =: 'Disposal'];
// Delete the assets
Database.DeleteResult[] drList = Database.delete(listtoDelete, false);
// Iterate through each returned result
for(Database.DeleteResult dr : drList) {
if (dr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully deleted account with ID: ' + dr.getId());
}
else {
for(Database.Error err : dr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Account fields that affected this error: ' + err.getFields());
}
}
}
#########################################################
}
}
All Answers
Regards
Jyoti
1) https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_scheduling_2.htm