You need to sign in to do that
Don't have an account?
Ally Abdool Latiff Mohabuth
need help to write a test class for batch finish method
Hello, i have a batch class. I need a test class for my finish method which send email. Here are my codes:
global void finish(Database.BatchableContext BC) { system.debug('accountsMap: ' + accountsMap); if(accountsMap != null && accountsMap.size() > 0){ Messaging.SingleEmailMessage mail = null; List<Messaging.singleEmailMessage> mailsList = new List<Messaging.singleEmailMessage>(); Id contactId = null; for(Order__c ord : accountsMap.values()){ if(ord.Account__r.Carer__c != null && ord.Account__r.Carer__r.IsCustomerPortal){ contactId = (ord.Account__r.Carer__r.PersonContactId != null) ? ord.Account__r.Carer__r.PersonContactId :null; }else if(ord.Account__r.IsCustomerPortal != null){ contactId = (ord.Account__r.PersonContactId != null) ? ord.Account__r.PersonContactId :null; } if(contactId != null){ List<EmailTemplate> template = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Stock_Due_Reminder' LIMIT 1]; if(template.size() > 0){ mail = new Messaging.SingleEmailMessage(); mail.setTemplateId(template[0].Id); mail.setTargetObjectId(contactId); mailsList.add(mail); } } }
Make sure you accountsMap should contain some value. Can you please post your full code
Please check below post for some more information
1) http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html
My full code