You need to sign in to do that
Don't have an account?
sonam guptha
Grabing the accounts even more than 60 days even
HI,
iam trying to send an email notification based on custom column,so here i have to send an email when my EndDate__c is less than 60 days,the below code is working fine but its grabing few accounts even more than 60 days,can i get any help to fix it?
i think iam not calculating right value here?
iam trying to send an email notification based on custom column,so here i have to send an email when my EndDate__c is less than 60 days,the below code is working fine but its grabing few accounts even more than 60 days,can i get any help to fix it?
i think iam not calculating right value here?
if(m.EndDate__c.daysBetween(D) < 60 )
global class expireNotify implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext bc) { //Date d = Date.today()+90; String soql = 'SELECT EndDate__c, Name FROM Account WHERE EndDate__c !=NULL'; return Database.getQueryLocator(soql); } global void execute(Database.BatchableContext bc, List<account> recs) { List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>(); Date D =Date.today(); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> toAddresses = new List<String>(); String messageBody; list<string> accstring =new list<string>(); integer i=0; for(account m : recs) { if(m.EndDate__c.daysBetween(D) < 60 ) { i+=1; messageBody = i+'-->'+ m.Name ; accstring.add(messageBody ); } } toAddresses.add('spnvarun0121@gmail.com'); mail.setToAddresses(toAddresses); mail.setSubject('Welcome to Sweet 16 Siebel Batch'); string allstring = string.join(accstring,'<br/>'); mail.setHtmlBody('<html><body>Hi Sir Hope you are well <br>'+'<br> List of accounts <br>'+allstring + ',<br>Your accounts Expires today. <br>Kindly contact your administrator.<br><br><b>Regards,</b><br>Magulan D<br/></body></html>'); mailList.add(mail); Messaging.sendEmail(mailList); } global void finish(Database.BatchableContext bc) { } }
2. It would make more sense to query for 60 days filter in SOQL itself.
Let me know if its retreiving records with diff or more than 61 days or so.
Replace your columns accordingly !
you can use
I Checkked in developer console its working fine