You need to sign in to do that
Don't have an account?
BATCH APEX ERROR in CODE
Hi Friends ,
Can anyone help me in resolving this code .
Error: Compile Error: Method does not exist or incorrect signature: [String].day() at line 19 column 37
// memberBirthdayBatch:
global class memberBirthdayBatch implements Database.batchable<Member__c>
{
global Iterable<Member__c> start(Database.batchableContext info)
{
System.debug('Start method');
return new callMemberIterable();
}
global void execute(Database.batchableContext info, List<Member__c> scope)
{
List<Member__c> memsToUpdate = new List<Member__c>();
System.debug('Member list size is ' + scope.size());
for(Member__c m : scope)
{
Date myDate = date.today();
Integer todayDy = myDate.day();
Integer todayMon = myDate.month();
System.debug('Day is ' + m.BirthDay__c.day());
Integer dy = m.BirthDay__c.day();
Integer mon = m.BirthDay__c.month();
if(todayDy == dy && todayMon == mon)
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<String> toAddresses = new List<String>();
toAddresses.add(m.EmailAddress__c);
email.setToAddresses(toAddresses);
List<String> ccAddresses = new List<String>();
ccAddresses.add('salesforcecrm@gmail.com');
email.setCcAddresses(ccAddresses);
email.setSubject('Happy Birthday. Have a blast -- Birthday Reminder!');
String message = '<html><table cellspacing = "7"><tr><td style="font-weight:bold;color:green;">Happy Birthday!!!</td></tr><tr><td style="font-weight:bold;color:pink;">Many more Happy returns of the day.</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td style="font-weight:bold;">Cheers,</td></tr><tr><td style="font-weight:bold;">XYZ</td></tr></table></html>';
email.setHtmlBody(message);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
}
}
}
global void finish(Database.batchableContext info)
{
}
}
Thanks in advance
All Answers
Can you please try this:
// retreive today's date
Date todayDate = Date.valueOf(System.today());
// retreives today's date and month separately
Integer day_today = todayDate.day();
Integer month_today = todayDate.month();
-Kaity
Hi Friends ,
Thanks a lot for ur help.
I have changed my field BirthDay__c on Member__c object to Date data type .