You need to sign in to do that
Don't have an account?
SV M
Unable to call opportunity name from list
I have a Batch Class where it sends an email when Expiry Date (Custom Date Field) is today. The mail body contains the list of opportunities whose Expiry Date is Today. I have created a list and added the opportunities whose Expiry Date is today. But I am stuck at calling Opportunity Name from the List. Can someone help me to solve this.
//Batch Class
global class OpportunityExpiryDate_New implements DataBase.Batchable <sObject> {
global DataBase.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Name, Expiry_Date__c FROM Opportunity WHERE Expiry_Date__c = TODAY';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
List<Opportunity> oppList = new List<Opportunity>();
for(Opportunity opp : scope) {
if(opp.Expiry_Date__c == date.today()) {
oppList.add(opp);
}
}
update oppList;
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
String body = 'The Opportunity ' +oppList+ ' is expiring today.';
email.setToAddresses(new String[]{'maddulasaivineeth@gmail.com'});
email.setSubject('Opportunities Expiring Today');
email.setPlainTextBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
global void finish(Database.BatchableContext BC) {
}
}
//Batch Class
global class OpportunityExpiryDate_New implements DataBase.Batchable <sObject> {
global DataBase.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Name, Expiry_Date__c FROM Opportunity WHERE Expiry_Date__c = TODAY';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
List<Opportunity> oppList = new List<Opportunity>();
for(Opportunity opp : scope) {
if(opp.Expiry_Date__c == date.today()) {
oppList.add(opp);
}
}
update oppList;
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
String body = 'The Opportunity ' +oppList+ ' is expiring today.';
email.setToAddresses(new String[]{'maddulasaivineeth@gmail.com'});
email.setSubject('Opportunities Expiring Today');
email.setPlainTextBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
global void finish(Database.BatchableContext BC) {
}
}
I have gone through your problem.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
All Answers
Were you able to recieve the email with the opportunity records?? or are you getting the issue while sending the email?
Please let me know the above.
Warm Regards,
Anutej Poddaturi
I have gone through your problem.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora