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

I created one BatchApex Class and i got some errors.
Here is my Batch Class. Below the class i mentioned errors as well.
global Class BatchApexContact Implements Database.Batchable<sobject>, Database.Stateful{
//Global Class BatchApexContact Implements Database.Batchable<sobject> {
Integer RecordProcessed = 0;
Integer RecordFailed = 0;
List<Contact> lstCon = new List<Contact>();
Integer NoOfTran = 0;
//start method
public Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator([Select id, FirstName, LastName from Contacts where FirstName like ' mm1']);
}
public void execute (Database.BatchableContext bc, List<Contact> con){
List<Contact> lstConFinal = new List<Contact>();
for(Contact C: con){
//Scenario Unsucessful Transaction
if(c.firstName ==mm1 && c.Lastname == 'nnn1'){
RecordProcessed = RecordProcessed+1;
c.firstname = A1;
c.LastName = B2;
lstConFinal.add(C);
lstCon.add(C);
} else {
RecordFailed = RecordFailed+1;
}
}
Update lstConFinal;
NoOfTran = con.size();
//end of Execute
// Finish Method
Public void finish (Database.BatchableContext bc){
AsyncApexJob job = [Select Id ,CreatedDate, CreatedByIdDate, JobType, ApexClassId, Status, JobItemsProcessed,
TotalJobItems, NumberOfErrors, CompletedDate, MethodName,
ExtendedStatus From AsyncApexJob where Id=: bc.getJobId()];
System.debug('*** JobId: '+bc.getJobId());
System.debug('*** job:' +job);
System.debug('*** Total no of Transactions: '+NoOfTran);
System.debug('*** Record Processed: ' +RecordProcessed);
System.debug('*** No of Records Failed : '+RecordFailed);
System.debug('*** List Of records Processed:' +lstCon);
System.debug('***How Many recs were Processed:' +lstCon.size());
}
}
}
1 Class BatchApexContact must implement the method: void Database.Batchable<SObject>.finish(Database.BatchableContext)
2Unexpected token 'Public'.
3Missing ';' at 'finish'
4Extra ')', at 'bc'.
global Class BatchApexContact Implements Database.Batchable<sobject>, Database.Stateful{
//Global Class BatchApexContact Implements Database.Batchable<sobject> {
Integer RecordProcessed = 0;
Integer RecordFailed = 0;
List<Contact> lstCon = new List<Contact>();
Integer NoOfTran = 0;
//start method
public Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator([Select id, FirstName, LastName from Contacts where FirstName like ' mm1']);
}
public void execute (Database.BatchableContext bc, List<Contact> con){
List<Contact> lstConFinal = new List<Contact>();
for(Contact C: con){
//Scenario Unsucessful Transaction
if(c.firstName ==mm1 && c.Lastname == 'nnn1'){
RecordProcessed = RecordProcessed+1;
c.firstname = A1;
c.LastName = B2;
lstConFinal.add(C);
lstCon.add(C);
} else {
RecordFailed = RecordFailed+1;
}
}
Update lstConFinal;
NoOfTran = con.size();
//end of Execute
// Finish Method
Public void finish (Database.BatchableContext bc){
AsyncApexJob job = [Select Id ,CreatedDate, CreatedByIdDate, JobType, ApexClassId, Status, JobItemsProcessed,
TotalJobItems, NumberOfErrors, CompletedDate, MethodName,
ExtendedStatus From AsyncApexJob where Id=: bc.getJobId()];
System.debug('*** JobId: '+bc.getJobId());
System.debug('*** job:' +job);
System.debug('*** Total no of Transactions: '+NoOfTran);
System.debug('*** Record Processed: ' +RecordProcessed);
System.debug('*** No of Records Failed : '+RecordFailed);
System.debug('*** List Of records Processed:' +lstCon);
System.debug('***How Many recs were Processed:' +lstCon.size());
}
}
}
1 Class BatchApexContact must implement the method: void Database.Batchable<SObject>.finish(Database.BatchableContext)
2Unexpected token 'Public'.
3Missing ';' at 'finish'
4Extra ')', at 'bc'.
try with below code.
If this helps, Please mark it as best answer.
Thanks!!