Metadata Type: SharingCriteriaRule
SharingCriteriaRule is a powerful Salesforce metadata type that allows administrators to define criteria-based sharing rules for objects. These rules automatically share records with users or groups based on field values, providing granular control over data access beyond organization-wide defaults and role hierarchies.
Overview
SharingCriteriaRule extends the base SharingRule metadata type and includes the following key fields:
- booleanFilter: A logical expression of conditions
- criteriaItems: A list of filter items defining the criteria
- includeRecordsOwnedByAll: Whether to include records owned by all users
Criteria-based sharing rules evaluate record field values to determine if they should be shared. This allows for dynamic, flexible sharing based on business logic rather than just record ownership.
Use Cases
Some common scenarios where SharingCriteriaRule is valuable include:
- Sharing high-value accounts based on annual revenue
- Granting access to sensitive records only when certain conditions are met
- Automatically sharing cases with specialized teams based on case attributes
- Implementing complex sharing models that can't be achieved with role hierarchies alone
Deployment Considerations
While SharingCriteriaRule offers powerful capabilities, there are several important factors to consider during deployment:
Performance Impact
Criteria-based sharing rules can have a significant impact on system performance, especially in orgs with large data volumes. Each time a record is created or updated, Salesforce must evaluate it against all criteria-based sharing rules. This can lead to slower save times and potential timeout issues.
Recalculation Time
When deploying new or modified sharing rules, Salesforce must recalculate sharing for all affected records. This process can take considerable time, potentially hours for large orgs. It's crucial to plan deployments during off-peak hours and communicate potential temporary access issues to users.
API Version Compatibility
Ensure that your deployment tools and processes are using a compatible API version. Some features of SharingCriteriaRule may only be available in newer API versions. Always review the Metadata API documentation for the specific version you're using.
Object Support
Not all objects support criteria-based sharing rules. Custom objects and some standard objects (like Account, Contact, Opportunity) support these rules, but many standard objects do not. Verify object compatibility before attempting to create or deploy SharingCriteriaRule metadata.
Validation Errors
Common deployment errors include invalid field references, unsupported filter operations, and conflicts with existing sharing settings. Thoroughly test sharing rules in a sandbox environment before deploying to production.
Best Practices for Administrators
To effectively use and manage SharingCriteriaRule metadata, Salesforce administrators should follow these best practices:
1. Limit Rule Complexity
Keep criteria as simple as possible. Complex boolean logic can be difficult to maintain and may impact performance. If possible, break complex rules into multiple simpler rules.
2. Monitor and Optimize
Regularly review sharing rule usage and performance. Use tools like the Sharing Rule Optimization report to identify rules that may be consolidated or simplified.
3. Use Selective Criteria
Choose criteria fields that will effectively limit the number of records that need to be shared. Overly broad criteria can lead to unnecessary sharing calculations.
4. Leverage Sharing Rule Evaluations
Understand how often your criteria fields change. Fields that rarely change (like Record Type) may be more efficient than frequently updated fields.
5. Plan for Scale
Consider future data growth when designing sharing rules. A rule that works well with 10,000 records may cause issues when you reach 1,000,000 records.
6. Document Thoroughly
Maintain clear documentation of your sharing model, including the purpose of each rule and any dependencies. This is crucial for long-term maintenance and troubleshooting.
7. Use Sharing Rule Recalculation Judiciously
Avoid frequent recalculations by batching changes when possible. Each recalculation can impact system performance.
8. Test in Sandbox
Always thoroughly test new or modified sharing rules in a sandbox environment with a representative data set before deploying to production.
9. Leverage Sharing Rule Evaluator
Use the Sharing Rule Evaluator tool to understand why specific records are (or aren't) shared and to troubleshoot unexpected sharing behavior.
10. Consider Alternatives
For very complex sharing requirements, evaluate whether criteria-based sharing rules are the best solution. Sometimes, Apex sharing or a custom sharing solution may be more appropriate.
Conclusion
SharingCriteriaRule is a powerful tool in the Salesforce administrator's toolkit for implementing sophisticated data sharing models. By understanding its capabilities, deployment considerations, and following best practices, admins can effectively use this metadata type to balance data security and accessibility needs. However, it's crucial to approach criteria-based sharing rules with careful planning and ongoing management to ensure optimal system performance and maintainability.