You need to sign in to do that
Don't have an account?
![Bilal 25 Bilal 25](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Need test class for batch apex
Please help me to create test class for this.
Thanks in Advance
public class FutureReceiptTriggerHandler{ Public static boolean blnTrigger = false; public static void sendEmail(set<Id> setFRIds, string strEmailReminder){ List<PDC_Management__c> lstFutureReceipts = [Select Id, Sales_Invoice__r.c2g__Account__r.c2g__CODAInvoiceEmail__c, First_Email_Sent__c, Second_Email_Sent__c, Third_Email_Sent__c from PDC_Management__c where Id IN: setFRIds]; EmailTemplate objEmailTemplate = new EmailTemplate(); String strOrgURL = URL.getSalesforceBaseUrl().toExternalForm() + '/'; system.debug('*************** strOrgURL == '+strOrgURL); String strFirstReminderTemplateId = ''; String strSecondReminderTemplateId = ''; String strThirdReminderTemplateId = ''; if(!Test.isRunningTest()){ if(strOrgURL == 'https://cs78.salesforce.com/'){ strFirstReminderTemplateId = '00X6E000000FXwy'; strSecondReminderTemplateId = '00X6E000000FZEK'; strThirdReminderTemplateId = '00X6E000000FZEK'; }else if(strOrgURL == 'https://um1.salesforce.com/'){ strFirstReminderTemplateId = '00XD0000002RTSp'; strSecondReminderTemplateId = '00XD0000002RTSu'; strThirdReminderTemplateId = '00XD0000002RTSz'; } if(strEmailReminder == 'First Reminder'){ objEmailTemplate = [Select Id, HtmlValue, Subject from EmailTemplate where Id =: strFirstReminderTemplateId limit 1]; }else if(strEmailReminder == 'Second Reminder'){ objEmailTemplate = [Select Id, HtmlValue, Subject from EmailTemplate where Id =: strSecondReminderTemplateId limit 1]; }else if(strEmailReminder == 'Third Reminder'){ objEmailTemplate = [Select Id, HtmlValue, Subject from EmailTemplate where Id =: strThirdReminderTemplateId limit 1]; } }else{ strFirstReminderTemplateId = 'Reminder_1_Rejected_Cheque_Notice'; strSecondReminderTemplateId = 'Reminder_2_Rejected_Cheque_Notice_2nd_Reminder'; strThirdReminderTemplateId = 'Final_Reminder_Rejected_Cheque_Notice_Immediate_action'; if(strEmailReminder == 'First Reminder'){ objEmailTemplate = [Select Id, HtmlValue, Subject from EmailTemplate where DeveloperName =: strFirstReminderTemplateId limit 1]; }else if(strEmailReminder == 'Second Reminder'){ objEmailTemplate = [Select Id, HtmlValue, Subject from EmailTemplate where DeveloperName =: strSecondReminderTemplateId limit 1]; }else if(strEmailReminder == 'Third Reminder'){ objEmailTemplate = [Select Id, HtmlValue, Subject from EmailTemplate where DeveloperName =: strThirdReminderTemplateId limit 1]; } } system.debug('************** objEmailTemplate == '+objEmailTemplate); List<OrgWideEmailAddress> lstOWE = [select Id, Address from OrgWideEmailAddress where Address = 'email1@email.ae']; List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for(PDC_Management__c objPDC : lstFutureReceipts){ if(objPDC.Sales_Invoice__r.c2g__Account__r.c2g__CODAInvoiceEmail__c != null){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> sendTo = new List<String>(); sendTo.add(objPDC.Sales_Invoice__r.c2g__Account__r.c2g__CODAInvoiceEmail__c); mail.setToAddresses(sendTo); List<String> sendCC = new List<String>(); sendCC.add('email3@email.ae'); mail.setCcAddresses(sendCC); List<String> sendBCC = new List<String>(); sendBCC.add('email4@email.ae'); mail.setBccAddresses(sendBCC); mail.setHtmlBody(objEmailTemplate.HtmlValue); mail.setSubject(objEmailTemplate.Subject); mail.setTreatBodiesAsTemplate(true); mail.setWhatId(objPDC.Id); mail.setSaveAsActivity(true); if(lstOWE.size() > 0){ mail.setOrgWideEmailAddressId(lstOWE[0].Id); }else{ mail.setReplyTo('email2@email.ae'); mail.setSenderDisplayName('person name'); } mails.add(mail); if(strEmailReminder == 'First Reminder'){ objPDC.First_Email_Sent__c = system.now(); }else if(strEmailReminder == 'Second Reminder'){ objPDC.Second_Email_Sent__c = system.now(); }else if(strEmailReminder == 'Third Reminder'){ objPDC.Third_Email_Sent__c = system.now(); } } } Messaging.sendEmail(mails); UPDATE lstFutureReceipts; } Public static void firstFRRejectUpdateAccountBucket(set<Id> setFRIds){ List<PDC_Management__c> lstFutureReceipts = [Select Id, Sales_Invoice__r.c2g__Account__c from PDC_Management__c where Id IN: setFRIds]; Set<Id> setAccountIds = new Set<Id>(); for(PDC_Management__c objPDC: lstFutureReceipts){ setAccountIds.add(objPDC.Sales_Invoice__r.c2g__Account__c); } AggregateResult[] groupedRejectedFR =[select count(Id)rejectedFR , Sales_Invoice__r.c2g__Account__c accId from PDC_Management__c where Status__c = 'Rejected' and Sales_Invoice__r.c2g__Account__c =: setAccountIds group by Sales_Invoice__r.c2g__Account__c]; Map<String,Integer> mapAccountwithBucketCount = new Map<String,Integer>(); for (AggregateResult ar : groupedRejectedFR) { if( Integer.valueOf(ar.get('rejectedFR')) > 0 && Integer.valueOf(ar.get('rejectedFR')) == 1 ){ mapAccountwithBucketCount.put(String.ValueOf(ar.get('accId')), Integer.valueOf(ar.get('rejectedFR'))); } } if(mapAccountwithBucketCount.size() > 0){ List<Account> lstAccount = [Select Id, Name, Bucket_Start_of_the_month__c from Account where Id IN: setAccountIds]; for(Account objAcc: lstAccount){ objAcc.Bucket_Start_of_the_month__c = mapAccountwithBucketCount.get(objAcc.Id); } update lstAccount; } } Public static void updateFRTLIN(set<Id> setFRIds){ map<Id,PDC_Management__c> mapTRNTOFR = new map<Id,PDC_Management__c>(); List<PDC_Management__c> lstFutureReceipt = [Select Id, Transaction_Line_Item__c, Amount__c, Is_Open__c from PDC_Management__c where Id IN: setFRIds]; for(PDC_Management__c objFR: lstFutureReceipt){ if(objFR.Transaction_Line_Item__c != null){ mapTRNTOFR.put(objFR.Transaction_Line_Item__c, objFR); } } if(mapTRNTOFR.size() > 0){ List<c2g__codaTransactionLineItem__c> lstTRNLI = [Select Id, Future_Receipts_1__c from c2g__codaTransactionLineItem__c where Id IN: mapTRNTOFR.keySet()]; if(lstTRNLI.size() > 0){ for(c2g__codaTransactionLineItem__c objTRNLI: lstTRNLI){ if(mapTRNTOFR.get(objTRNLI.Id).Is_Open__c == true){ objTRNLI.Future_Receipts_1__c = mapTRNTOFR.get(objTRNLI.Id).Amount__c ; }else{ objTRNLI.Future_Receipts_1__c = 0; } } update lstTRNLI; } } } }
Thanks in Advance
![](/forums/img/s.gif)
![](/forums/img/s.gif)
I recommend building the test class based on the example provided in this Trailhead Module