Posted: 4 May 2020 19:26 EDT Last activity: 7 May 2020 4:06 EDT
Error handling in database operations
I usually write database operation as below - Pega-New, Property-Set, Obj-Save, and Commit. I don't know how to write error handling if anything goes wrong during these steps, but I think this is not great. For example, shouldn't I always include Rollback steps? If so, where and how? Or, if there are any more standard practice to handle error, please let me know. Screenshot helps.
***Edited by Moderator Marissa to updat General to Product; update platform capability tags***
You can use OOTB activity CommitWithErrorHandling which will take care of the rollback if any error during the commit operation and it will also do the necessary work objects unlocking if you select the commit on release option in Obj-open or Obj-open by handle during the current transactional process.
Thanks for the info. What if the target object is a Data instance instead of Work instance? This commitWithErrorHandling API is placed at Work- class, and therefore I am not able to call it for Data instance?
You can use jump condition to check the step status on obj-save step. If stepstatus is good then you can continue to the next step. Else you can log a message or set the error(using @pxAddMessageToPage function). Generally, the log message is used in agent activities. And one more best practice is to remove the temppage.
1. Without using this function, Pega will not record the error implicitly. You can also use the Page-set-messages method to set the error. But without using any method or function Pega will not record the error implicitly.
2. Instead of the commit method, you can call CommiwithErrorHandling.If this activity is used and the commit fails the activity itself takes care of rollback.