Please find my below code that is getting list index out of bound exception.
Apex Class:
global class Incidentimp_2 implements Database.Batchable < sObject > {
public string query = 'SELECT DM_Lookup_id__c FROM Incident__c where createddate<>today';
global database.querylocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List < Incident__c > scope) {
//Map<Inventory_Wishlist__c, Product2> temp = new Map<Inventory_Wishlist__c, Product2>();
Set < ID > IdSet = new Set < ID > {};
// Map<string,string> xyz=new Map<string,string>();
// EmailTemplate emailTemplate = [select Id, Body from EmailTemplate where DeveloperName = 'POC_DM'];
//List<Incident__c> soorders = (List<Incident__c>)scope;
//Map<ID, String> salesOrderMap = new Map<ID,String>();
for (Incident__c so: scope) {
IdSet.add(so.DM_Lookup_id__c);
}
List < User > usr = [select Email, id, Name from User where id in : IdSet];
for (User u: usr) {
list < string > txtbody = new list < string > ();
txtbody[0] = 'Dear ' + u.Name + ',';
txtbody[1] = 'New non-compliant cases have been assigned to you in Aspire. \n';
txtbody[2] = 'Please review and resolve all issues within two weeks. \n';
txtbody[3] = 'or Late Code Subcategory is changed \n';
String plaintxtbody = String.join(txtbody, '/n');
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] {
'[email protected]'
});
email.setToAddresses(new String[] {
'[email protected]'
});
email.setSaveAsActivity(false);
email.setTargetObjectId(u.Id);
//email.setTemplateId(emailTemplate.Id);
email.setPlainTextBody(plaintxtbody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {
email
});
}
}
global void finish(Database.BatchableContext BC) {
}
}