Monday, August 4, 2014

Validation, Approval Process and Testing

Two of the common sources of headache for Salesforce developer is approval process and validation.  Because these are declarative aspect of Salesforce (i.e. configured through the Salesforce user interface) with some restriction, these can be difficult to manager and migrate

With it being now migratable, many of the pain points for developing approval process in the sandbox has been removed.  However, once you activate an approval process, Salesforce removes some of the functionalities.  You can find more about these limitations here, but I found the following to be particularly difficult to deal with when you have changes in business logic and need to modify the approval process:

  • You cannot delete active approval process, and you can't deactivate an approval process if there is any records that are submitted for approval (you have to hard delete those records).
  • Once you activate an approval process, you can't add, delete or change the orders of the approval step even if you deactivate them.



With the validation rule, the difficulty I sometimes encounter is when trying to migrate some code and there is additional validation rule in the destination org (e.g. production or QA sandbox).  These validation rule can cause your test methods to fail in the destination org even though it has passed in the development org.  You can either create those validation rule in your development org and refactor your test methods to meet the validation rule, or if you are confident that the additional validation rule will not cause the business logic error when the new code is deployed, you can temporarily disable to the validation rule in the destination org during the migration and re-activate it afterwards.