You need to sign in to do that
Don't have an account?
Problem with using Database.delete() method
At the first i am sorry about my English, but there are no resources except this to solve the problem with apex coding.
So I'll try to explain problem.
I need to make the part of code that would delete accounts which names have already written by user;
And of course I need to catch possible exceptions, so i try to use
List<Database.DeleteResult> deleteResults = Database.delete(DeleteIdList);
and after that try to process List of deleteResults in the loop and check errors.
But it isn't work like i want. When record couldn't deleted generated DMLException. Why? I didn't use any DML, i only used database method.
Will be thankfull for any ideas.
yes, actually database.delete take two argument.
The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why.
I hope this helps.
All Answers
Are you trying to do something like this?
No I didn't. Because yours variant offer to use DML, so when one record couldn't be deleted it must cause an exception and other wouldn't processed.
As a suggest with documentation, database method Delete() must process all record and write possible errors in appropriate Database.DeleteResult object instead of causing an exception. And I need this opportunity to delete all records for which it possible and display other.
But in practice database method Delete() also generate an exception when record cannot be deleted. Am i do something wrong?
yes, actually database.delete take two argument.
The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why.
I hope this helps.
Very very thank you. So easy solution, and it works=). May you give link to source when this method described? It might be useful, and might stops me from future treatments here.
Sure, Force.com Apex Code Developer's Guide