You need to sign in to do that
Don't have an account?
Matt1000
Delete OpportunityLineItem results in error DML currently not allowed
The following code is supposed to delete all products from the current Opportunity:
delete [ Select Id from OpportunityLineItem WHERE OpportunityID = :ApexPages.currentPage().getParameters().get('id') ];
...but it results in this error:
"DML currently not allowed"
The email generated to me from Salesforce about the error says:
System.LimitException: DML currently not allowed
Note: I am using Developer Edition.
Can anyone explain why this code is failing?
Thanks!
Hi Matt,
There are several reasons why you facing this error:
1) You are operating DML in constructor, which is not allowed.
2) DML operation within a component controller.
If you facing the problem due to first scenario then use:
YouDMLOpertaingMethod will delete the records, this method will be called after constructor is loaded.
And if you are facing the the problem due to second scenario then try this :
Hope this will help you out.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
Hi,
Check out the exception. It shows that you have crossed your governor limits.
That is why you are getting this kind of error. Try to optimize your code so that you will cross the governor limits.
Also Using Delete [Query] is also not good practice.
Hope this will help you!! For any help let me know!!
Hi Matt,
There are several reasons why you facing this error:
1) You are operating DML in constructor, which is not allowed.
2) DML operation within a component controller.
If you facing the problem due to first scenario then use:
YouDMLOpertaingMethod will delete the records, this method will be called after constructor is loaded.
And if you are facing the the problem due to second scenario then try this :
Hope this will help you out.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Thanks Ankit_Arora!
I was trying to execute this DML statement in the constructor, so your 1st suggestion solved my issue.
P.S. I had started with a safer form for the delete statement, escaping the id parameter, etc., but I pared the delete statement down to the simple form shown for discussion in this forum.
Thanks again!