Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- General Development
- :
- Delete trigger is returning an error
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Delete trigger is returning an error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-28-2012 07:49 AM
I am working on year end processes and need to delete some zero records from a custom object. I have written a trigger that will fire when a field on a custom object is set to YES for delete zero records. The trigger appears to be working correctly until ready to delete the record. I am getting the following error.
EXCEPTION_THROWN|[28]|System.DmlException: Delete failed. First exception on row 0 with id a0AJ0000005AY6fMAG; first error: ENTITY_IS_DELETED, entity is deleted: []
09:37:48.247 (1247331000)|FATAL_ERROR|System.DmlException: Delete failed. First exception on row 0 with id a0AJ0000005AY6fMAG; first error: ENTITY_IS_DELETED, entity is deleted: []
Here is the Trigger code:
trigger DeleteZeroOrders onStart_Budget__c (afterupdate) {
if(trigger.isUpdate)
{
Start_Budget__c sb = [Select Delete_Zero_Open_Orders__c fromStart_Budget__c];
system.debug('Delete Open Orders = ' + sb.Delete_Zero_Open_Orders__c);
If(sb.Delete_Zero_Open_Orders__c == 'Yes'){
List<Open_Order__c> OrdersToDelete = new List<Open_Order__c>();
for(Open_Order__c o : [Select Id,Current_Year_YTD__c,Future_Year_YTD__c fromOpen_Order__c])
{
system.debug('Selected Open Orders = ' + o);
if(o.Current_Year_YTD__c == 0){
IF(o.Future_Year_YTD__c == 0){
OrdersToDelete.add(o);
system.debug('Orders to Delete = ' + OrdersToDelete);
}
}
If(OrdersToDelete.size() != 0)
Delete OrdersToDelete;
}
}
}
}
Solved! Go to Solution.
Re: Delete trigger is returning an error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-29-2012 07:39 PM
Hi Max,
Please try by putting 'Delete' command out side of for loop.
This error may cause we are not clearing the list and in second cycle we are trying to delete the the id which has been deleted in first cycle.
Ranu
Salesforce.com Certified Developer
Re: Delete trigger is returning an error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 09:16 AM
Thanks for the update. Worked great.

