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
Dilyan DimitrovDilyan Dimitrov 

Rolling back DML operation in Apex method

Hello,

The problem that I am having is that I am using addError method in before insert trigger which actually rollback every DML I make including @future method calls, sending email, queueing batch jobs, or performing any DML. What I would like to know is
how to stop the process of converting Lead to Account and at the same time dispaly message in the convert page as well as to set and update a custom Lead status field to 'Existing Deal'.

To be more precise what I need to acheve:
1. Stop the process of converting Lead to Account. 
2. Display message in the convert Lead to Account page that the respective Lead is not converted.
3. Set and Update the Lead.Status__c field to 'Existing Deal'.

Apparently this can't be achieved by using the addError method and I will strongly appreciate if you can advise how to proceed and find a solution to this issue?
 
sachin kadian 5sachin kadian 5
Hi Dllyan,

If you are using addError, you cant stop rollbacking . Whenever any error is there, it will automatically rollback every DML happened in that transaction. So you cant update any field. 

Please have a look on these links-

http://salesforce.stackexchange.com/questions/10624/can-i-prevent-an-insert-to-be-rolled-back-even-if-my-class-later-runs-into-an