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
Afrose AhamedAfrose Ahamed 

delete failed. first exception on row 0 with id xxxxxxxxxx; first error: entity_is_deleted, entity is deleted: []

Hi All,
​​​​​​In batchapex when multiple user tries to update or insert same record or same user at multiple times tries to insert or update on same record at same time  Im getting the following error delete failed. first exception on row 0 with id xxxxxxxxxx; first error: entity_is_deleted, entity is deleted: []. 

I really appreciate if someone explain. It will be a great help to me to understand better.

Here is my code:(sometimes happened too many dml rows error in batchapex reducing the batch size to 50 it's fixed)
 
Trigger Updaterec on courses__c (After Insert, After update) {
List<string>studentids =new List<string>();
For(courses__c  course:trigger.new){
Studentids.add(course.students__c);
}
<students__c> students = [select I'd,schools__c from students__c where id IN:studentids];
List<string> schoolids =new list<string>();
For(students__c sc:students){
schoolids.add(sc.school__c);
}
Mycontroller.updateschool(schoolids);
}

Apex class
Public with sharing class Mycontroller{
Public static void updateschool(list<string>schoolids){
Integer Counts = [select count(Id)number from schools__c where id IN:schoolids].get('number');
If(Counts<4000){
List<schools__c> oldschoollist =[select Id, name from schools__c where id IN:schoolids];
Dmlhandler.delete(oldschoollist);
//Again querying the same school and its related record inserting as new records with user newly added records
/*Logic goes here
*
*
*
*/
Dmlhandler.Insert(newschoollist);
}else{
batchlogic batch = new batchlogic(schoolids);
batch.schoolids=schoolids;
Database.Executebatch(batch);
}
}
}

Batch apex
Public with sharing class Mycontroller{
Public static void updateschool(list<string>schoolids){
Integer Counts = [select count(Id)number from schools__c where id IN:schoolids].get('number');
If(Counts<4000){
List<schools__c> oldschoollist =[select Id, name from schools__c where id IN:schoolids];
Dmlhandler.delete(oldschoollist);
//Again querying the same school and its related record inserting as new records with user newly added records
/*Logic goes here
*
*
*
*/
Dmlhandler.Insert(newschoollist);
}else{
batchlogic batch = new batchlogic(schoolids);
batch.schoolids=schoolids;
Database.Executebatch(batch);
}
}
}

Regards,
Afrose​​​​​​​
Afrose AhamedAfrose Ahamed
Sorry the error message is System.DmlException: Insert failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []
Irenne SmithIrenne Smith
Whenever I need to do any student stuff, I research the options of online sources that I would use. For example, a scholarship essay writing service has assisted me in obtaining a budgetary place at my dream university of digital engineering. https://edubirdie.com/scholarship-essay-writing-service is a source that can guide a lot of students 'cause these academic experts are worth trusting. Try their quality knowledge and support, and I wish you good luck!