+ Start a Discussion
pooja biswaspooja biswas 

exception handling in apex

Hi
I have a class which will update account field and contact field if some change occurs in opportunity.
I am calling instance of this class inside trigger written on opportunity object.

I am using Database.Update statement to perform DML .
Now if an error occurs while updating the contact field, then I should roll back the entire transaction including account.

Please let me know how to achieve this.

Thanks
Pooja
Arshadulla.ShariffArshadulla.Shariff
Hello pooja,

Try specifying a boolean parameter allorNone along the with list of sobject to update .
For Eg:
Database.update(ListofAccounts,true);
This will rollback all the transaction in the context .
check for the following method in Database class.
update(recordToUpdate, allOrNone)
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database.htm

Please let us know, if this solves your problem.
Thanks