Salesforce Flows are incredibly powerful in simplifying business processes. Salesforce Flows when coupled with validation rule becomes an automation powerhouse in itself and works seamlessly for scaling and simplification of complex scenarios.
Business Requirement
Whenever a new case is created, all users will be able to set the priority of the case. However, the business wants to restrict the users to update the priority of the case. In the case of re-prioritization, only a couple of Op-leads would be able to update it provided one of the case feedback records is marked as Approved for Prioritisation. Case Feedback is a custom object which is in a look-up relationship with the case and contains a status field with values- Approved to Close, Approve to Prioritise, Rejected
Solution Proposition
We need to consider a couple of scenarios while defining the solution.
As we are considering only a couple of users in the system, so it wouldn't be a good practice to create a new profile.
A simple validation rule will not suffice.
Based on the above analysis, our solution outline will be as follows-
Broadly, we will require the following configuration to meet the aforesaid business requirement-
Step 1- Create a new custom permission called Update_Priority_OpsLead
Step 2- Create a new field on Case called Invoke_Validation__c. The flag will be hidden from the layout and as the name suggests, we will be invoking the validation rule using this field.
Step 3 - Create a new Validation rule on the Case which will check Invoke_Validation__c = True only on case updates
Step 4 - Create a record-triggered flow(Before update) which will validate if the custom permission is applied to the user and also validate if any of the case feedback records are marked as Approved to Prioritise.
Based on the above, our flow will look as below-
Let's take a look at all of the Flow Elements-
Step 1- Setup the record-triggered flow for Case with flow optimized for Fast Field Updates with entry check on changing of Case Priority
Step 2- Validate if the user is eligible to update case priority by leveraging Custom permission(Update_Priority_OpsLead)
Step 3- Query the related object called Case Feedback with a check on the case id. Store all the fields and query all records.
Step 4- Create a loop and traverse through all the records matching to the stated criteria.
Step 5- Validate if any of the records contains the status of Approved to Prioritise. If found, let the user update the records.
Step 6- If step 5 is not true, add a value to the counter and continue to do so for all the records found in the loop. Use a similar variable at the top as well.
Step 7- Validate if the counter variable was visited in the flow. If yes, set the Invoke_Validation__c field as True on the case. This will trigger the validation rule and will restrict the users to update the case priority.
Hope you enjoyed this post.
The above post could be extended to multiple use cases. Please let me know in the comment section how you leveraged the above to solve your use-case.