You need to sign in to do that
Don't have an account?
Batch Apex
Hi Developers ,
Im new to SFDC .
Can anyone help me in this coding part where im facing an ERROR.
Error: Compile Error: unexpected token: ')' at line 14 column 61
// Sample prg to Delete the records of object a using Batch Apex.
global class Deletea implements Database.Batchable
{
global final string query;
global deletea__c(string q);
{
query=q;
}
global Database.QueryLocator start(Database.Batchablecontext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List <scope>)
{
list<a__c> lista= new list<a__c>();
for(Sobjects s :scope)
{
(a__c) a = (a__c)s;
lista.add(a)
}
Delete lista;
}
global void finish(Database.Batchablecontext BC)
{
//Send an email to the User after your batch complete
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] ToAddresses = new String[] {‘xyz@gmail.com’};
mail.setToAddresses(ToAddresses);
mail.setSubject('Apex Batch Job is done‘);
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Thanks in Advance
Relpace your Execute method with following.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
All Answers
Hi Nikkey,
there are some syntax errors in your batch class.
i have solved it. you can use below code.
Batch Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
I think you need to change finish method. like this:
Much Better.
Thanks,
Samba
Hi Hitesh ,
Thanks for u help.
But i stil get some error as :
Error: Compile Error: Variable does not exist: a at line 13 column 23global class Deletea implements Database.Batchable<sObject>{
global final string query;
global deletea(string q){
query=q;
}
global Database.QueryLocator start(Database.Batchablecontext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<sObject> scope){
list<a__c> lista= new list<a__c>();
for(Sobject s :scope){
//(a__c) a = (a__c)s;
lista.add(a);
}
Delete lista;
}
global void finish(Database.Batchablecontext BC){
//Send an email to the User after your batch complete
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] ToAddresses = new String[] {'xyz@gmail.com'};
mail.setToAddresses(ToAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
for(Sobject s :scope){
//(a__c) a = (a__c)s;---> remove //
lista.add(a);
}
Thanks,
Samba
Relpace your Execute method with following.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
Hi Hitesh ,
Thanks Alot For ur help .
when i replace the sobject with the object name in execute method its wrkg.
// Sample prg to Delete the records of object a using Batch Apex.
global class Deletea implements Database.Batchable<sObject>
{
global final string Query;
global deletea(string q)
{
Query=q;
}
global Database.QueryLocator start(Database.Batchablecontext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<a__C> scope)
{
list<a__c> lista= new list<a__c>();
for(a__C a :scope)
{
lista.add(a);
}
Delete lista;
}
global void finish(Database.Batchablecontext BC)
{
//Send an email to the User after your batch complete
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] ToAddresses = new String[] {'salesforcecrm@gmail.com'};
mail.setToAddresses(ToAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Note:
Please let me know if you have any questions.
Thanks,
Samba