function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lingannalinganna 

batch apex class run

 

hi all

iam getting the email but records not deleted and in developer console displaying

 

24.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: Id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from Account'),10);
23:39:01.051 (51627000)|EXECUTION_STARTED
23:39:01.051 (51640000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
23:39:01.051 (51742000)|VARIABLE_SCOPE_BEGIN|[1]|batchinstanceid|Id|false|false
23:39:01.052 (52262000)|STATEMENT_EXECUTE|[1]
23:39:01.052 (52272000)|STATEMENT_EXECUTE|[1]
23:39:01.054 (54858000)|METHOD_ENTRY|[1]|01pU0000000xjRc|deleteAccounts.deleteAccounts()
23:39:01.054 (54869000)|STATEMENT_EXECUTE|[1]
23:39:01.055 (55004000)|SYSTEM_MODE_ENTER|false
23:39:01.055 (55021000)|HEAP_ALLOCATE|[1]|Bytes:5
23:39:01.055 (55030000)|STATEMENT_EXECUTE|[1]
23:39:01.055 (55039000)|SYSTEM_MODE_EXIT|false
23:39:01.055 (55049000)|METHOD_EXIT|[1]|deleteAccounts
23:39:01.055 (55069000)|HEAP_ALLOCATE|[1]|Bytes:8
23:39:01.055 (55078000)|HEAP_ALLOCATE|[1]|Bytes:22
23:39:01.055 (55121000)|CONSTRUCTOR_ENTRY|[1]|01pU0000000xjRc|(String)
23:39:01.055 (55158000)|VARIABLE_SCOPE_BEGIN|[4]|this|deleteAccounts|true|false
23:39:01.055 (55186000)|HEAP_ALLOCATE|[3]|Bytes:8
23:39:01.055 (55212000)|VARIABLE_ASSIGNMENT|[4]|this|{}|0x2cb7594f
23:39:01.055 (55221000)|VARIABLE_SCOPE_BEGIN|[4]|q|String|false|false
23:39:01.055 (55236000)|VARIABLE_ASSIGNMENT|[4]|q|"select Id from Accou (2 more) ..."
23:39:01.055 (55249000)|STATEMENT_EXECUTE|[1]
23:39:01.055 (55259000)|SYSTEM_MODE_ENTER|false
23:39:01.055 (55267000)|HEAP_ALLOCATE|[3]|Bytes:5
23:39:01.055 (55275000)|STATEMENT_EXECUTE|[3]
23:39:01.055 (55287000)|SYSTEM_MODE_EXIT|false
23:39:01.055 (55300000)|SYSTEM_MODE_ENTER|false
23:39:01.055 (55306000)|HEAP_ALLOCATE|[3]|Bytes:5
23:39:01.055 (55312000)|STATEMENT_EXECUTE|[5]
23:39:01.055 (55316000)|STATEMENT_EXECUTE|[6]
23:39:01.055 (55364000)|VARIABLE_ASSIGNMENT|[6]|this.Query|"select Id from Accou (2 more) ..."|0x2cb7594f
23:39:01.055 (55375000)|SYSTEM_MODE_EXIT|false
23:39:01.055 (55399000)|CONSTRUCTOR_EXIT|[1]|01pU0000000xjRc|(String)
23:39:01.055 (55431000)|SYSTEM_METHOD_ENTRY|[1]|Database.executeBatch(APEX_OBJECT, Integer)
23:39:01.101 (101186000)|HEAP_ALLOCATE|[1]|Bytes:15
23:39:01.101 (101206000)|SYSTEM_METHOD_EXIT|[1]|Database.executeBatch(APEX_OBJECT, Integer)
23:39:01.101 (101232000)|HEAP_ALLOCATE|[1]|Bytes:18
23:39:01.101 (101257000)|VARIABLE_ASSIGNMENT|[1]|batchinstanceid|"707U0000003azznIAA"
23:39:01.783 (104487000)|CUMULATIVE_LIMIT_USAGE
23:39:01.783|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  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: 3 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  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 10

23:39:01.783|CUMULATIVE_LIMIT_USAGE_END

23:39:01.104 (104521000)|CODE_UNIT_FINISHED|execute_anonymous_apex
23:39:01.104 (104529000)|EXECUTION_FINISHED
bob_buzzardbob_buzzard

I think you'll need to post some code for us to help on this one.

lingannalinganna

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[] {'linganna09@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 });  
}  
}

bob_buzzardbob_buzzard

The code looks fine.  What does the query look like? You might also want to consider adding some debug statements to the execute method to check how many records are in the scope parameter.

lingannalinganna

Id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from Account'),10);

i have written i system log page. i am gettin mail but records not deleted.

bob_buzzardbob_buzzard

You log shows 0 DML statements, which implies that the delete isn't firing for some reason.  Hence the suggestion of adding debug statements to the execute method to output the scope size and show the progress through the execute method.

lingannalinganna

Id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from Account'),10);

i have written the above code  in system log page. i am getting mail but records not deleted.

bob_buzzardbob_buzzard

You've posted the same response again - was that intentional.

nagalakshminagalakshmi

Hi linganna,

 

You have try like this. Its delete all account records

string query= [select id from account];

batchupdatefield batch=new batchupdatefield(query);

Database.executebatch(batch,200);

 

Thanks