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

Apex code for email alert?
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 i.e 10 mail, but i want one email need to send which contain all 10 opportunity list in table.that can be done through schedular class.i tried my self but i am not getting the exact result.
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('Syed.Akram@cyient.com');
mail.setToAddresses(toAddresses);
//Email subject to be changed
mail.setSubject('Opportunity Expired');
//Body of email
mail.setHtmlBody('Hi ');
}
}
Please find the solution. You have to implement Batchable and Schedulable interface to achieve the desired goal. Please modify the code based on your requirement. I did not implement the date manipulation part.