+ Start a Discussion
Internal PartnerInternal Partner 

Best practices when testing / deploying triggers and trigger handlers

Hi all,

I am learning little by little with all experiences in projects in the last week.
One of them: Our Development team built a trigger that lets an external system synchronize the account address to their contact addresses and validates with an error message if any user tries to update the contact addresses. After deploying it to the Production environment, users could not create contacts anymore.

We spent time analyzing what was going on and found out there were workflows overlapping the trigger in the way that any user can update the contact addresses through the respective account. Workflows were given everytime a Contact record is created or updated.

And here my question, is this problem with the workflows something we could have avoided? could we have foreseen this conflict between the workflows and the trigger?. We didn't know that these workflows existed as these were built by another admin who then left the project.
SFDC Prime SquadSFDC Prime Squad
Hi Team,
Writing Test methods and test classes is the best way we can run through all our test cases and scenrios. This also helps to test both positive and negative scenarios and figure out if the code actually covers all the scenarios. Using asserts in test methods confirms the expected output and helps in analyzing the gaps if any.

More details on best practices for test classes can be found here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm
Deepali KulshresthaDeepali Kulshrestha
Hi ,

Please refer to these links it may helpful to you.
http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html
https://salesforce.stackexchange.com/questions/155645/trigger-best-practices-updating-multiple-related-objects
https://www.forcetalks.com/salesforce-topic/what-are-the-advantages-of-using-handler-classes-in-trigger/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha