1

I have the below batch code

global class BatchClassAccountSched implements Database.Batchable<SObject>, Database.AllowsCallouts, Schedulable {

global Database.Querylocator start(Database.BatchableContext BC) {
    String query = '';
    if(Test.isRunningTest()){
            query = 'SELECT ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet FROM Account WHERE Location__Latitude__s = null and Location__Longitude__s = null and ShippingStreet != null and ShippingCity != null and ShippingCountry != null and ShippingPostalCode != null and ShippingState != null and Owner.CEE_Sales_Group_Code__c != null limit 100';            
           system.debug('####query'+query);
        }
      else{
          query = 'SELECT ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet FROM Account WHERE Location__Latitude__s = null and Location__Longitude__s = null LIMIT 100';
          system.debug('@@@@ACCOUNT'+query);
      }
      system.debug('boh: '+Database.getQueryLocator(query));
       return Database.getQueryLocator(query);
}  

global void execute(Database.BatchableContext bc, List<Account> scope) {
    system.debug('in execute');

 // create an address string
        List<Account> newListAcc = new List<Account>();
        for(Account accountNew : scope){

            //stuff with a try-catch 

       } 
       system.debug('*****NUOVA LISTA ACCOUNT : ' + newListAcc);
       update newListAcc;
       system.debug('*****@@@'+newListAcc);
       system.debug('*****@@@'+newListAcc.size());


}

/*global void execute(SchedulableContext sc) {
        Database.executeBatch(this, 100);
    }*/

global void execute(SchedulableContext sc) {
    system.debug('prima');
    Id batchJobId = Database.executeBatch(new BatchClassAccountSched());
    system.debug('dopo');
}

global void finish(Database.BatchableContext BC){
   }


}

but when i call it with

Database.executeBatch(new BatchClassAccountSched());

I do not see any debug from the execute method... why do you think this happen? I have tried to see the logs and they stop here. What is going on?

21:47:57.045 (45637604)|USER_DEBUG|[11]|DEBUG|@@@@ACCOUNTSELECT ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet FROM Account WHERE Location__Latitude__s = null and Location__Longitude__s = null LIMIT 100
21:47:57.045 (45644992)|SYSTEM_METHOD_EXIT|[11]|System.debug(ANY)
21:47:57.045 (45649162)|STATEMENT_EXECUTE|[13]
21:47:57.045 (45654232)|HEAP_ALLOCATE|[13]|Bytes:5
21:47:57.045 (45670639)|SYSTEM_METHOD_ENTRY|[13]|Database.getQueryLocator(String)
21:47:57.049 (49800773)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|SELECT ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet FROM Account 
21:47:57.088 (88418169)|SOQL_EXECUTE_END|[13]|Rows:100
21:47:57.088 (88492872)|HEAP_ALLOCATE|[13]|Bytes:20
21:47:57.088 (88517854)|SYSTEM_METHOD_EXIT|[13]|Database.getQueryLocator(String)
21:47:57.088 (88586282)|SYSTEM_METHOD_ENTRY|[13]|String.valueOf(Object)
21:47:57.088 (88608813)|HEAP_ALLOCATE|[13]|Bytes:204
21:47:57.088 (88623643)|SYSTEM_METHOD_EXIT|[13]|String.valueOf(Object)
21:47:57.088 (88632638)|HEAP_ALLOCATE|[13]|Bytes:209
21:47:57.088 (88644424)|SYSTEM_METHOD_ENTRY|[13]|System.debug(ANY)
21:47:57.088 (88652136)|USER_DEBUG|[13]|DEBUG|boh: Database.QueryLocator[Query=SELECT ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet FROM Account WHERE Location__Latitude__s = null and Location__Longitude__s = null LIMIT 100]
21:47:57.088 (88660061)|SYSTEM_METHOD_EXIT|[13]|System.debug(ANY)
21:47:57.088 (88665921)|STATEMENT_EXECUTE|[14]
21:47:57.088 (88674854)|SYSTEM_METHOD_ENTRY|[14]|Database.getQueryLocator(String)
21:47:57.089 (89004818)|SOQL_EXECUTE_BEGIN|[14]|Aggregations:0|SELECT ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet FROM Account 
21:47:57.157 (157240924)|SOQL_EXECUTE_END|[14]|Rows:100
21:47:57.157 (157305681)|HEAP_ALLOCATE|[14]|Bytes:20
21:47:57.157 (157329828)|SYSTEM_METHOD_EXIT|[14]|Database.getQueryLocator(String)
21:47:57.195 (195203238)|CUMULATIVE_LIMIT_USAGE
21:47:57.195 (195203238)|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
  Maximum CPU time: 0 out of 60000
  Maximum heap size: 0 out of 12000000
  Number of callouts: 0 out of 0
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 0
  Number of queueable jobs added to the queue: 0 out of 1
  Number of Mobile Apex push calls: 0 out of 10

2 Answers 2

5

Execute runs in a different transaction, so it will be in a different log. You should have three logs altogether, one for start, one for execute, and one for finish. It shows that 100 rows were selected (so, one iteration, or execution, should fire), so you need to find the next log after that one. If the LIMIT were higher, or omitted entirely, you could have many logs generated from running that command, depending on the volume of accounts that met your criteria.

6
  • 'you cannot call a batch from the execute function, so it probably generated an exception log' what do you mean exactly?
    – tony danza
    Commented Jul 17, 2015 at 20:15
  • @tonydanza Exactly what I meant. You cannot call another batch while inside a batch. They only allow System.executeBatch in the finish function. This is to prevent explosive resource usage.
    – sfdcfox
    Commented Jul 17, 2015 at 20:22
  • I don't get it.. where am i calling the batch while inside the batch? i think i have just implemented 2 execute method - one for SchedulableContext and the other for BatchableContext.
    – tony danza
    Commented Jul 17, 2015 at 20:27
  • 1
    @tonydanza You're right. I misread that part. Regardless, you're still missing a log somewhere.
    – sfdcfox
    Commented Jul 17, 2015 at 20:35
  • I have tried opening all the logs I get but I dont see anything else. Me sad.
    – tony danza
    Commented Jul 17, 2015 at 20:40
0

Try -

global void execute(Database.BatchableContext bc, **List<sObject>** scope) 

intead of -

global void execute(Database.BatchableContext bc, List<Account> scope) 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .