5

I have developed triggers on a managed package object which gets updated through a webhook service. The webhook updates some external id and status fields which are critical to get updated regardless if any of my custom code fails. I am thinking of putting exception handling throughout my code and handling errors through updating an error field and getting an email whenever something goes wrong.

This implementation is for a large enterprise client and the project is growing more complex each day. I want to make sure I am using the best practice for handling this scenario. Thanks for the help.

5

You can't perfectly guard your own triggers against your clients' folly. If they break it, they have to undo whatever they did to break it. For example, they could add a required unique indexed field, or a validation rule that causes problems, or triggers with null pointer exceptions, or flows that do unusual things to your data.

Your best hope is simply to try and test as many normal use circumstances as you can, and accept the fact that your clients can break your code. Really, it's more like selling cars with a warranty. Basically, you warranty that you'll fix problems that are your fault, but if they do something to void that warranty, they have to fix it themselves.

Some ISVs are also consultants, and they offer hourly rates to fix problems that they cause, or extend the application in supported ways so that it doesn't break the code. It's unreasonable to expect that you can possibly guard against anything the client may do to break your code.

|improve this answer|||||
  • let me clarify bit more. I am actually developing triggers in a client org. on an sobject that is part of a managed package. Although, that managed package is developed by us and I have access to the code. Thing is, there is so much customisation needed by clients that there is always chance of a silly exception occurring. Now the managed package app is actually a transaction processing system and we have to make sure whatever happens with custom code, the managed package code gets executed i.e. dml changes gets submitted. – Mustafa Turab Ali Sep 16 '16 at 22:17
  • let me clarify bit more. I am actually developing triggers in a client org. on an sobject that is part of a managed package. Although, that managed package is developed by us and I have access to the code. Thing is, there is so much customisation needed by clients that there is always chance of a silly exception occurring. Now the managed package app is actually a transaction processing system and we have to make sure whatever happens with custom code, the managed package code gets executed i.e. dml changes gets submitted. – Mustafa Turab Ali Sep 16 '16 at 22:18
  • @MustafaTurabAli I've actually been wishing that something like this were possible, but there's simply too many things that can't be can't be accounted for. The worst of them are governor limits. Governor limits are (mostly) uncatchable and cause an abrupt termination with no chance of recovery. Until salesforce gives us a guaranteed fail-safe mechanism, or a way to bypass validation errors, etc, most of the major things that can go wrong can't be recovered from. Inevitably, things will go wrong and need to be fixed. Code defensively, but understand that defenses are not impenetrable. – sfdcfox Sep 16 '16 at 22:25
  • Thanks once again for providing great insights. I found something which may not be 100% bulletproof but a good starting point. Idea is to maintain a queue of events for the records in an sobject for all kinds of critical updates. We can serialise the data and put it into an sobject when call fails. Then either create some kind of retry process using scheduler or a button on the record to retry update. Again this is for a connected system where update went through in one system but didn't reflected in SF. – Mustafa Turab Ali Sep 26 '16 at 9:06
  • We can configure no. of retries and also send out reports to admin/tech dept. to checkout. On most occasions, on screen information about failure will help users/admin figure out and resolve issue. – Mustafa Turab Ali Sep 26 '16 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.