1

I am trying to create a simple delete trigger that deletes a task as soon as the task is created. I have very little background using APEX/creating triggers. Here is my trigger below:

trigger DeleteTasksSept on Task (after insert) {

    for(Task DelTask : Trigger.new){
        if(DelTask.IsDeleted != TRUE){
            List<Task> delta = [SELECT ID, OwnerID FROM Task WHERE OwnerID = '0051400000BMa8N'];
            delete delta;
        }
    }
}

When I test this by creating a new Task I am getting a validation error after I click save that says:

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "common.exception.SfdcSqlException: ORA-20008: ORA-06512: at "DOPEY.CACCESS", line 129 ORA-06512: at "DOPEY.CACCESS", line 110 ORA-06512: at "DOPEY.CACTIVITYACCESS", line 1270 ORA-06512: at "DOPEY.CACCESS", line 2943 ORA-06512: at "DOPEY.CACCESS", line 2771 ORA-06512: at line 1 SQLException while executing plsql statement: {call cAccess.check_entity_access_proc_ncu(?,?,?,?,?,?)}(EXCLUDED, EXCLUDED, 00T56000003vdPx, EXCLUDED, true, false)".

Has anyone ever seen this error message before? Is there something wrong with the syntax of my trigger? Any help would be greatly appreciated!

Adrian Larson
  • 149,971
  • 38
  • 239
  • 420

2 Answers2

3

You have found one of the Seven Dwarves. Contact support immediately. From that answer (emphasis mine):

The Seven Dwarfs live in the platform code. You should never see DOPEY, SLEEPY, DOC, GRUMPY, SNEEZY, BASHFUL, or HAPPY, but occasionally they break out and appear to a user. If you spot one of them, you need to contact support so they can be put back in their dwarfy walled garden.

Adrian Larson
  • 149,971
  • 38
  • 239
  • 420
1

This can be accomplished more efficiently. Just to ensure you are doing what the code is suggesting - You are deleting ALL tasks associated with a given user as the owner whenever any task is inserted.

Also, no need to check for isDeleted since the query does not return deleted records unless you tell it to.

I would have moved this to a batch process but it seems like you want immediate deletion so.....

trigger DeleteTasksSept on Task (after insert) {

    database.deleteResult[] dr = database.delete([Select ID From Task Where OwnerId = '0051400000BMa8N'],false);

}

Now, you should also not be hardcoding the ID so you may want to query for the user id and use the returned value.

Additionally, you may want to do something in case of errors as the above code will not throw any errors if there was a problem deleting the records (the false part of the database.delete code)

You can check errors by adding

for(integer x-0;x<dr.size();x++){
     if(!dr[x].isSuccess()){

         //Do something with the record that was not deleted

     }
}

While the above may not get to the cause of the error it may allow you have code that works. I would still follow Adrian's advice and submit a ticket to see what the issue was in the first place.

Eric
  • 54,152
  • 11
  • 100
  • 195
  • Eric - Thank you for the reply and the suggestion. I created a new trigger using your suggestion and got the same error. This time it replaced "Dopey" with "Grumpy". I have a ticket out with Salesforce so I will update when I get a response from them, Thanks! – Stephen Davlantes Sep 20 '16 at 19:48
  • @user1360011 - What if you add the delete to an future method? – Eric Sep 20 '16 at 20:20
  • Eric - Instead of trying to muck around with that trigger I took your suggestion and added a class with the following code and i'm going to run it once a day. This should do the trick so thanks for the help!

    global class ScheduledDelete Implements Schedulable { global void execute(SchedulableContext sc) { massDelete(); } public void massDelete() { List <task> listtoDelete = [Select ID From Task Where OwnerId = '0051400000BMa8N']; delete listtoDelete; } }

    – Stephen Davlantes Sep 21 '16 at 13:11