You need to sign in to do that
Don't have an account?
Gm Chouhan
Nested Batch Apex Calling
i have writed 2 batch apex
--------------------------
1 st
-------------------
global class AccountBatchApex1 implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext bc)
{
System.debug('Account Batch Apex1 Staring...........111111111111111')
String query='SELECT Phone FROM Account limit 1 order by desc';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Account> scope){
for(Account a:scope){
a.phone+=1;
}
update scope;
}
global void finish(Database.BatchableContext bc){
System.debug('Ok Account Batch Apex1 fineshed.........11111111111111111');
AccountBatchApex2 aba2 = new AccountBatchApex2();
Database.executeBatch(aba2);
}
}
-----------------------------------
2nd
---------------------------
global class AccountBatchApex2 implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext bc)
{
System.debug('Account Batch Apex2 Staring...........2222222222222222')
String query='SELECT name, Phone FROM Account limit 1 order by desc';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Account> scope){
for(Account a:scope){
a.phone+=1;
}
update scope;
}
global void finish(Database.BatchableContext bc){
System.debug('OK Account Batch Apex 2 finished.........2222222222');
AccountBatchApex1 aba1 = new AccountBatchApex1();
Database.executeBatch(aba1);
}
}
--------------------------
phone no = 10
but no method execution......pls help
--------------------------
1 st
-------------------
global class AccountBatchApex1 implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext bc)
{
System.debug('Account Batch Apex1 Staring...........111111111111111')
String query='SELECT Phone FROM Account limit 1 order by desc';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Account> scope){
for(Account a:scope){
a.phone+=1;
}
update scope;
}
global void finish(Database.BatchableContext bc){
System.debug('Ok Account Batch Apex1 fineshed.........11111111111111111');
AccountBatchApex2 aba2 = new AccountBatchApex2();
Database.executeBatch(aba2);
}
}
-----------------------------------
2nd
---------------------------
global class AccountBatchApex2 implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext bc)
{
System.debug('Account Batch Apex2 Staring...........2222222222222222')
String query='SELECT name, Phone FROM Account limit 1 order by desc';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Account> scope){
for(Account a:scope){
a.phone+=1;
}
update scope;
}
global void finish(Database.BatchableContext bc){
System.debug('OK Account Batch Apex 2 finished.........2222222222');
AccountBatchApex1 aba1 = new AccountBatchApex1();
Database.executeBatch(aba1);
}
}
--------------------------
phone no = 10
but no method execution......pls help
change the query to:SELECT name,Phone FROM Account order by Lastmodifieddate limit 1
thanks,
RAmesh
All Answers
change the query to:SELECT name,Phone FROM Account order by Lastmodifieddate limit 1
thanks,
RAmesh
Change your query from
String query='SELECT Phone FROM Account limit 1 order by desc';
to
This should work !!
If this helps,please mark it as best answer to help others :)