You need to sign in to do that
Don't have an account?

How to send email alert with schedular apex class?
Hi i want to send the email to opportunity owner for the upcoming opportunities which is expiering next week.
You need to sign in to do that
Don't have an account?
why don't you try to do it with a workflow and a time based action? is much easier this way. You can schedule the email alert date with no code at all. Give it a try and let me know if you need more help :)
Regards,
Form Workflow we can send one mail at a time.
My requiremenrt is suppose i have 10 opportunity with same closed date with same opportunity owner then workflow will send 10 mail to same address, So i want one email need to send which contain all 10 opportunity list in table.
hope you understand my requirement.
In that case, the workflow will send 1 notification 10 times, I mean, they are treated indepently as long as they apply the criteria of the workflow rule.
Regards,
i have written some code but i am unable to get the desired output. Can anyone help me to update code .
global class Opp_Scheduled Implements Schedulable
{
Map<Id , List<Opportunity>> oppMap {get; set;}
global void execute(SchedulableContext sc)
{
setopplist();
}
public void setopplist()
{
Date d = Date.today();
//Map to maintain opportunity id
oppMap = new Map<Id, List<Opportunity>>() ;
//All opportunity closeDate
List<Opportunity> opplist = new List<Opportunity>() ;
opplist = [select id, name, Owner.id, StageName, closeDate from Opportunity where CloseDate >= :d AND CloseDate <=:d-7];
List<Id> Idlist = new List<Id>() ;
for(Opportunity opp : opplist )
{
Idlist.add(opp.owner.id) ;
}
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
List<String> toAddresses = new List<String>();
mail.setTemplateId('00Xe0000000RUOp');
//Setting user email in to address
toAddresses.add('******EmailId********');
mail.setToAddresses(toAddresses);
//Email subject to be changed
mail.setSubject('Opportunity Expired');
//Body of email
mail.setHtmlBody('Hi ');
}
}