One of the best things about programming on the Salesforce platform is the wealth of resources online to help problem solve. It can be one of the worst things about programming on the platform as well if you aren't careful about the resources you choose to follow. Some code samples use outdated practices, others may be snippets of code taken out of context, which may not behave as expected in a different context.
In one case, the Apex documentation team included System.assert statements in a code snippet. Our new developer later copied the snippet into a utility class. The developer found a great resource but didn't fully understand the difference between System.assert and System.debug. The former builds in a fatal error, appropriate for test code but not for our essential platform automations. Sniffing out this cargo cult programming helped us know what additional training could help our developers.
A more frequently found cargo cult is the factory class to build basic objects. A factory class is still far better than using the very outdated SeeAllData in your test code. But test data factory classes add unnecessary work for coders. Salesforce offers a newer and better technique with Test.loadData, which I wrote about in July. It lets us shift the work of creating and maintaining sample data from the developer to the administrator.
Other cargo cult programming that pops up in our Salesforce org relates to data sharing and security rules. We teach our developers early on to understand the difference between code that runs only in Triggers vs code that may be run by end-users via UI customizations like pages, flows and actions. And we encourage our administrators to monitor org security in our code during code reviews and test executions.
Hunting out and eliminating cargo cult programming helps us build cohesion among the team that maintains our Salesforce platform and better understanding between administrators and developers who now work more closely together. This helps us spread the effort of org maintenance across a team and make use of clicks and code for our projects. End users benefit and our org is more reliable and easier to maintain as well.
No comments:
Post a Comment