0

i have a batch class with code

public class BatchDeleteEvents implements Database.Batchable, Database.Stateful, Database.AllowsCallouts {

private String query;
private String pageToken ;
private String CalendarId;
private String accessToken;
public BatchDeleteEvents(String CalendarId, String accessToken){

    this.query = 'Select Id, Name from Event__c'; // Query to get the CalendardID (Google ID)
this.CalendarId =CalendarId;
this.accessToken =accessToken;
}

public Database.Querylocator start(Database.BatchableContext BC){

    return Database.getQueryLocator(query);

}

public void execute(Database.BatchableContext BC, List<sObject> scope){
System.debug('Entered in delete Batch');
for(Event__c c : (List<Event__c>)scope)
 GCalendarUtil.doApiCall(null,'DELETE','https://www.googleapis.com/calendar/v3/calendars/'+CalendarId+'/events/'+c.name,accessToken);


    delete scope;
    }
public void finish(Database.BatchableContext BC){   
  for(CalendarSettings__c c: [Select Id, Name, CalendarId__c,CalendarQuery__c,FieldToDisplay__c from CalendarSettings__c])
     {  BatchPublicCampaignsToGoogle bjob = new BatchPublicCampaignsToGoogle(c.CalendarQuery__c,c.CalendarId__c,c.FieldToDisplay__c);
        Database.executeBatch(bjob,9); // This is set to process 9 records, allowing 1 extra callout for refresh token in case needed.
    }
    }

    }

and i am running it with batch of 9

BatchDeleteEvents del = new BatchDeleteEvents(c.CalendarId__c,accessToken); Database.executeBatch(del,9);

and i am facing error

FATAL_ERROR|System.DmlException: Delete failed. First exception on row 0 with id a0290000007fCbEAAU; first error: ENTITY_IS_DELETED, entity is deleted: []

Class.BatchDeleteEvents.execute: line 26, column 1

there is no place where i am using delete command why i am facing this error any one please help ??

mathlearner
  • 7,509
  • 31
  • 126
  • 189
  • Hi All I have same problem.Can you please click this link http://salesforce.stackexchange.com/questions/42537/unable-to-delete-the-records-rows-in-trigger See the log I a have got same issue. – Ramesh Somalagari Jul 11 '14 at 03:46

1 Answers1

4

Maybe you delete all scope in for loop change it to

for(Event__c c : (List<Event__c>)scope){
  GCalendarUtil.doApiCall(null,'DELETE','https://www.googleapis.com/calendar/v3/calendars/'+Cal   endarId+'/events/'+c.name,accessToken);

 }
 delete scope;
Shimshon Korits
  • 1,189
  • 6
  • 10