You need to sign in to do that
Don't have an account?
penchala raju
can i send a data through mail from finish() method whatever i fetched from batch apex execute method.can any only .please see the below code
global class batchupdate implements Database.Batchable<sobject>
{
// list<account> s{set;get;}
global Database.QueryLocator start(Database.BatchableContext bc)
{
String Query = 'select id,Transaction_type__c,amount_info__c from Transaction__c';
System.debug('------Query---->'+Query);
return Database.getQueryLocator(Query);
}
global void execute(Database.BatchableContext bc,list<Transaction__c> scope)
{
// s=new list<account>();
list<Transaction__c> cust=new List<Transaction__c>();
System.debug('------scope---->'+scope.size());
// scope=s;
for(Transaction__c c:scope)
{
c.amount_info__c=5656;
cust.add(c);
// system.debug(cust);
}
update cust;
}
global void finish(Database.BatchableContext bc)
{
Messaging.SingleEmailMessage mail1=new Messaging.SingleEmailMessage();
String[] toadd=new String[]{'praju.salesforce@gmail.com'};
mail1.setToAddresses(toadd);
mail1.setSubject('Test mail');
mail1.setPlainTextBody('this is a test mail');
Messaging.SingleEmailMessage mail2=new Messaging.SingleEmailMessage();
mail1.setToAddresses(toadd);
mail1.setSubject('Test mail');
mail1.setPlainTextBody(list<Transaction__c> cust);
Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail1});
}
}
{
// list<account> s{set;get;}
global Database.QueryLocator start(Database.BatchableContext bc)
{
String Query = 'select id,Transaction_type__c,amount_info__c from Transaction__c';
System.debug('------Query---->'+Query);
return Database.getQueryLocator(Query);
}
global void execute(Database.BatchableContext bc,list<Transaction__c> scope)
{
// s=new list<account>();
list<Transaction__c> cust=new List<Transaction__c>();
System.debug('------scope---->'+scope.size());
// scope=s;
for(Transaction__c c:scope)
{
c.amount_info__c=5656;
cust.add(c);
// system.debug(cust);
}
update cust;
}
global void finish(Database.BatchableContext bc)
{
Messaging.SingleEmailMessage mail1=new Messaging.SingleEmailMessage();
String[] toadd=new String[]{'praju.salesforce@gmail.com'};
mail1.setToAddresses(toadd);
mail1.setSubject('Test mail');
mail1.setPlainTextBody('this is a test mail');
Messaging.SingleEmailMessage mail2=new Messaging.SingleEmailMessage();
mail1.setToAddresses(toadd);
mail1.setSubject('Test mail');
mail1.setPlainTextBody(list<Transaction__c> cust);
Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail1});
}
}
Yes you can send that data. what is the issue you are facing in that.
Thanks,
Himanshu
Please check following code
there are two things which I have added.
1. Database.Stateful interface at the top which will maintain state throughout the execution
2. global Trans_List which can be used to retain record so that we can get processed record in finish method.
Let me know if you have any question
Thanks,
Himanshu