Wednesday, November 23, 2016

Best practices and desing patterns for declarative development

As we all know that salesforce provides a rich set of declarative development features such as validation rules, workflows, process builders etc. These declarative features are optimized to work with the force.com architecture and provides us with some default degree of SOC. Having said that as an admin / developer there are few best practices or patterns that you can introduce in your declarative development. 

Make your validation rules, process builders and workflows mutable by design

Having Validation Rules, Workflow and Process builders in your Salesforce org is a great way to implement your business process. However, I can think of more than one scenario where ValidationWorkflow Rules and Process builders can get in your way. To avoid such scenarios always ensure that your declarative components are mutable by design
.

Step 1: Create a hierarchy custom setting


Step 2: Create custom field (checkbox) for each validation rules, If your organization has more than 300 validation rules, you should create 1 custom setting per object.


Step 3: Update validation rules to By Pass based on the value in custom setting


Step 4: When you want to bypass a validation rule, create a record in the custom setting. You can create record for a user or profile or at org level.





Step 5: The same logic can be applied to workflow rules and process builders.

Filter based on record type

If you have record types enabled for objects, always ensure that your validation rules, workflows, process builders and approval process are filters on record type name. Even if the process is global and applicable to all record types its recommended to apply record type filters. This will ensure that any future development or expansion in your org will not impact your existing codes.

Sample: Add RecordType.DeveloperName check after your user/profile bypass check




Add more focus to your declarative components

Ensure that the entry criteria is narrowed down to the relevant events. For eg: Validation rules are executed every-time a record is created or modified, its recommended to narrow down the scope to change in values of the relevant fields.

Sample: Add isNew() isChanged(Field Name) check after record type check.







No comments:

Post a Comment