Activity Forums Salesforce® Discussions Is it is possible to force to store information even if the trigger throws an exception?

  • PRANAV

    Member
    September 6, 2016 at 6:25 am

    Hi Tanu,

    There is a way to prevent a DML operation from succeeding without causing the whole apex transaction to be rolled back (like @future, emails, DML, etc.): the sObject.addError method. If you call this method on every sObject in your trigger it will prevent them all from being committed to the database, however any other DML operations you perform (that of course, do not cause errors in their own triggers) will be committed successfully.

    If you're looking to log to a custom object this is your best bet; catch the exception, mark everything in Trigger.new with addError, then commit your log sObject.

    Hope this helps you.

    Thanks

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos