Forcetrails: Troubleshoot test failure in Salesforce production

Have you ever came across this scenario where your test methods run like a charm in the sandbox but fail in production? Here are some guidelines which might help you in this situation.
Let us first understand the reason behind this.
Sometimes, people write validation rules, workflows, process builders and other automation directly in production (I know it's not recommended, and we should always go through sandboxes or whatever deployment process is set in your organization.), or other code changes might be deployed from another sandbox that is not there in the sandbox that you have tested your code. Another reason could be some critical updates activated in production.

Here are some guidelines to troubleshoot this.
  • Check the debug logs which are generated while deployment that contains debug logs for the test execution. Most of the time you catch the issue here.
  • While checking debug logs run the specific tests which are failing.
  • Try running existing related tests from production, to see if the problem is in existing changes. If yes, you need to fix that as well.
  • Check the labels/custom setting/custom metadata values if any.
  • Make sure you don't have empty catch blocks in your code and test classes. At least a debug logs should be there. If you have an empty catch block, exceptions go unnoticed.
  • Check if all branching statements are being covered. Let's say you have an if block which is a bigger portion in your code, which is not being covered by your test class in production. This doesn't give you an error but results in low code coverage. So the debug logs are your only friends in these situations.
  • Don't write try/catch blocks in your test method unless it is required.
3 comments:

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at rahul@forcetrails.com