You need to sign in to do that
Don't have an account?
ch ranjith
Not updating field in student with Batch apex Please help me
global class batchstudent implements Database.Batchable<sobject>
{
global final String Query;
global batchstudent(String q)
{
Query=q;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<student__C> scope)
{
List <student__C> lstAccount = new list<student__C>();
for(Sobject s : scope)
{
student__C a = (student__C)s;
a.status__c='updated from batch apex';
system.debug(a);
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
asyncapexjob a=[select id,status,numberoferrors,jobitemsprocessed,totaljobitems
from asyncapexjob where id=:bc.getjobid()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ranjith.imp@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed '+a.totaljobitems+'batches with'+a.numberoferrors+'failures');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
developer console:
id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from student__c'));
{
global final String Query;
global batchstudent(String q)
{
Query=q;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<student__C> scope)
{
List <student__C> lstAccount = new list<student__C>();
for(Sobject s : scope)
{
student__C a = (student__C)s;
a.status__c='updated from batch apex';
system.debug(a);
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
asyncapexjob a=[select id,status,numberoferrors,jobitemsprocessed,totaljobitems
from asyncapexjob where id=:bc.getjobid()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ranjith.imp@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed '+a.totaljobitems+'batches with'+a.numberoferrors+'failures');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
developer console:
id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from student__c'));
Duplicated from https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AcGMIA0 please use original post.
Please mark my answer as a best solution to your question to help others if it solves your problem.