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
Haystack CertifiedHaystack Certified 

Will savepoint prevent exceptions in triggers from rolling back the entire transaction

Suppose there is a trigger where I don't want exceptions to rollback the entire transaction.  Can savepoints help here?  i don't want to suppress any errors by wrapping a try/catch around everything.  if the trigger gets to a certain point, then the transaction should save regardless of downstream exceptions.
Best Answer chosen by Haystack Certified
David Catindoy 101David Catindoy 101
Then Database.update(recordToInsert, allOrNone) is what you're going to use. Database.insert above is just a sample, but the explanation and the syntax is the same. Please read the link to know more about it.

All Answers

David Catindoy 101David Catindoy 101
Try using Database class, for example: Database.insert(recordToInsert, allOrNone).

The optional 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.

Visit this link (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database.htm#apex_System_Database_insert) for more info.
Haystack CertifiedHaystack Certified
Database.insert would be good if the trigger was inserting additional records on another object and some of the transactions on the other object failed.  My issue is an error occuring on the record that is being updated.
David Catindoy 101David Catindoy 101
Then Database.update(recordToInsert, allOrNone) is what you're going to use. Database.insert above is just a sample, but the explanation and the syntax is the same. Please read the link to know more about it.
This was selected as the best answer