You need to sign in to do that
Don't have an account?
nagalakshmi
How to run the batch apex class
Hi,
My batch apex class for deleting the account records is
global class deleteAccounts implements Database.Batchable<Sobject>
{
global final String Query;
global deleteAccounts(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<Account> lstAccount = new list<Account>();
for (SObject s : scope) //for all objects from our query
{
Account a = (Account)s;
lstAccount.add(a);
}
Delete lstAccount;
}
global void finish(Database.BatchableContext BC)
{
//Send an email to the User after your batch completes
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'nagalakshmi_b@dskvap,com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Now i want to execute the this code for deleting the records. how to execute this? can any one help me.
Thanks,
lakshmi.
This is only the debug log of Start method.
Aren't you getting any other logs? (logs of execute method and finish methods)
It is retrieving 200 records.
Better you add Scope while executing.
Id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from Account'),10);
Hope this helps..
Regards,
Shravan
All Answers
Execute your batch Apex from system log.
Id batchId = database.executeBatch(new deleteAccounts(your query), scope);
scope defines the Batch Size. i.e., how many records to be processed at a time. (default is 200)
Regards,
Shravan
Hi,
I use this code
Id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from Account'));
I recieved a mail apex job is finished but records are not deleted in accounts.please help me.
thanks,
lakshmi.
have you check the debug logs. Does any error printed?
Regards,
Shravan
Hi shravan,
No i did not get any errors in system log. And i get the message as
14:11:53.882|CUMULATIVE_LIMIT_USAGE_END
14:11:53.345|CODE_UNIT_FINISHED|deleteAccounts
14:11:53.345|EXECUTION_FINISHED
at the end of the system log. And i recieved a mail as The batch Apex job processed. Please help me out.
Thanks in advance.
Lakshmi.
I have executed your code and it is working fine....
I don't know why it is happening to you? Did you check how many records were retreived through the query?Any triggers on Account?
can you show the entire log when the batch is executed?
Regards,
Shravan
Hi Shravan,
My entire log when i am excute the batch
21.0APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:11:53.026|EXECUTION_STARTED
14:11:53.026|CODE_UNIT_STARTED|[EXTERNAL]|01p90000000ROOW|deleteAccounts
14:11:53.070|METHOD_ENTRY|[15]|BatchableContextImpl.BatchableContextImpl()
14:11:53.070|METHOD_EXIT|[15]|BatchableContextImpl
14:11:53.074|METHOD_ENTRY|[1]|01p90000000ROOW|deleteAccounts.deleteAccounts()
14:11:53.074|METHOD_EXIT|[1]|deleteAccounts
14:11:53.074|METHOD_ENTRY|[12]|Database.getQueryLocator(String)
14:11:53.107|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select Id from Account
14:11:53.165|SOQL_EXECUTE_END|[12]|Rows:200
14:11:53.165|METHOD_EXIT|[12]|Database.getQueryLocator(String)
14:11:53.177|METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
14:11:53.177|METHOD_EXIT|[7]|QueryLocatorIterator
14:11:53.882|CUMULATIVE_LIMIT_USAGE
14:11:53.882|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 200
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of script statements: 1 out of 1000000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 0
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 0
14:11:53.882|CUMULATIVE_LIMIT_USAGE_END
14:11:53.345|CODE_UNIT_FINISHED|deleteAccounts
14:11:53.345|EXECUTION_FINISHED
can you please tell me where the mistake is going on..
Thanks,
Lakshmi
This is only the debug log of Start method.
Aren't you getting any other logs? (logs of execute method and finish methods)
It is retrieving 200 records.
Better you add Scope while executing.
Id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from Account'),10);
Hope this helps..
Regards,
Shravan
Hi Sravan,
Thank you very so much. Its working fine. Can you tell me how to write the batch apex for inserting the records in to object.
Thanks,
Lakshmi
Same way as you have done the deletion of records.
return the list of records from start method and insert those records in Execute method.
Regards,
Shravan
hi...
i want run the below interface program please help me outthis anyone.
public class InterfaceClass
{
public Interface bankTransactionInterface
{
double deposit();
double withdrawal();
}
public class BankA implements bankTransactionInterface
{
public double deposit()
{
double depositedAmount = 250;
system.debug('@@@@@@@@depositedAmount'+depositedAmount);
return depositedAmount ;
}
public double withdrawal()
{
//process the withdrawal
double withdrawalAmount = 350;
system.debug('@@@@@@@@withdrawalAmount '+withdrawalAmount );
return withdrawalAmount ;
}
}
public virtual class BankB implements bankTransactionInterface
{
public virtual double deposit()
{
double depositedAmount = 450;
system.debug('@@@@@@@@depositedAmount '+depositedAmount);
return depositedAmount ;
}
public double withdrawal()
{
double withdrawalAmount = 1000;
system.debug('@@@@@@@@withdrawalAmount '+withdrawalAmount );
return withdrawalAmount ;
}
}
public class BankC extends BankB
{
public override double deposit()
{
//process the deposit
double depositedAmount = 750;
system.debug('@@@@@@@@depositedAmount '+depositedAmount);
return depositedAmount ;
}
}
}