<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=6676386&amp;fmt=gif"> Skip to main content

A Guide to Salesforce Anti-Patterns

article banner

Quick Glance.

Salesforce implementations often fall victim to common pitfalls, known as Anti-patterns . These include over-reliance on a single individual ("Hero"), excessive automation without proper governance ("Automation Bonanza"), and complex, poorly documented systems ("Big Ball of Mud"). Other anti-patterns include inflexible solutions ("Pieism"), convoluted sharing models ("Spaghetti Sharing Model"), and the overuse of Apex triggers. Delve into these anti-patterns, current trends, and future projections, identify ways to avoid them, and help your organization build more efficient, and maintainable Salesforce systems.


 

Introduction

Salesforce Anti-Patterns are common pitfalls or mistakes that organizations often encounter when implementing Salesforce. These anti-patterns can lead to various issues, including performance problems, poor user experience, increased maintenance costs, and security vulnerabilities.In the world of Salesforce, anti-patterns refer to common mistakes or approaches that might seem like a good idea initially but ultimately lead to problems down the line. These can impact system performance, user experience, maintainability, and overall effectiveness of your Salesforce implementation. Here are some common examples:

1. The Hero:

This arises when a single person or small group becomes the sole point of knowledge and expertise for managing the Salesforce system. While their contributions are valuable, it creates a single point of failure and makes the system vulnerable if these individuals leave or become unavailable.

2. Automation Bonanza:

This occurs when organizations over-automate processes without proper planning and governance. This can lead to complex workflows, conflicting automations, and unexpected behavior, making it difficult to manage and troubleshoot issues.

3. The Big Ball of Mud:

This describes a system that has grown organically over time, lacking clear structure and documentation. This makes it difficult to understand how the system works, maintain it, and implement new features.

4. Pieism:

This refers to the belief that one solution or approach can fit all situations. When it comes to Salesforce customizations, applying the same solution to every unique business need can lead to inefficiencies and limit the platform's potential.

5. Spaghetti Sharing Model:

This describes a complex and convoluted sharing model where users have access to data based on intricate and hard-to-understand rules. This can lead to data security issues, difficulty managing user permissions, and confusion for users trying to access the information they need

6. The Golden Hammer

This pattern refers to the practice where one tool or technology which might be perfect for a particular use case is considered perfect for all the use cases. This is due to the success of this approach in the previous projects, but it leads to over-reliance on this one solution.

7. Overuse of Apex Triggers:

Apex triggers, while powerful, can become performance bottlenecks or introduce unexpected behaviour if not used judiciously. Here are 10 pointers to avoid common overuses

  • Excessive Bulkification: Avoid unnecessary loops within triggers. Instead, leverage the bulkification nature of triggers to process multiple records efficiently.
  • Complex Logic: Keep trigger logic as simple and focused as possible. Avoid intricate calculations or business rules that can be better handled in Apex classes or flows.
  • Recursive Calls: Recursive trigger calls can quickly lead to stack overflow errors. Ensure your trigger avoids self-references or indirect recursion.
  • Excessive SOQL Queries: Minimize SOQL queries within triggers, especially those that query the same records multiple times. Consider using a map to store queried data for reuse.
  • Excessive DML Operations: Limit DML operations within triggers, as they can trigger additional triggers and potentially lead to infinite loops.
  • Asynchronous vs. Synchronous: Choose the right execution context for your trigger. Synchronous triggers can block user interactions, while asynchronous triggers might introduce delays.
  • Trigger Order: Be mindful of trigger order, as it can affect the execution sequence and potentially lead to unexpected results.
  • Testing and Coverage: Thoroughly test your triggers to ensure they function correctly under various scenarios. Maintain adequate code coverage to minimize the risk of unintended consequences.

Alternatives: Explore alternative approaches like flows, process builders, or Apex classes when appropriate. These tools can often provide more efficient or maintainable solutions.

  • Performance Monitoring: Regularly monitor trigger performance to identify potential bottlenecks. Use tools like Salesforce's Performance Analyzer to diagnose issues and optimize your code.

8. Ignoring Governor Limits:

Governor Limits are essential for maintaining the stability and performance of the Salesforce platform. Ignoring or circumventing them can lead to serious consequences, such as:

  • Performance degradation: Excessive resource consumption can impact the overall performance of the platform, affecting all users.
  • Data corruption: Incorrectly handling Governor Limits can lead to data inconsistencies or loss.
  • Account suspension: Salesforce may act against accounts that repeatedly violate Governor Limits.

Instead of trying to bypass Governor Limits, focus on writing efficient Apex code that adheres to them. Here are some important pointers to help you optimize your code:

  • Bulkify DML operations: Process multiple records at once using a single DML statement to reduce the number of database calls.
  • Minimize SOQL queries: Use a map to store query results and avoid redundant queries.
  • Optimize query filters: Use selective filters to retrieve only the necessary data.
  • Leverage batch jobs: For large data sets, use batch jobs to process data in manageable chunks.
  • Use asynchronous processing: For long-running tasks, use asynchronous processes like batch jobs or future methods to avoid blocking the user interface.

By following the above guidelines, we can write an efficient and scalable Apex code that respects Governor Limits and ensures the optimal performance of your Salesforce application.

9. Poor Data Model Design:

A well-structured data model is crucial for the performance, scalability, and maintainability of your Salesforce application. Here are 5 common pitfalls to avoid in your data model design:

  • Over-Normalization: Excessive normalization can lead to complex relationships and increased query complexity. While normalization is important, strive for a balance between data integrity and query efficiency.
  • Incorrect Field Types: Using inappropriate field types can impact data storage, retrieval, and validation. For example, storing numbers as text fields can hinder calculations and comparisons.
  • Redundant Data: Storing the same data in multiple fields or objects can lead to inconsistencies and maintenance challenges. Consider using relationships or lookup fields to avoid redundancy.
  • Lack of Referential Integrity: Ensuring referential integrity helps maintain data consistency and prevents orphaned records. Use relationships and validation rules to enforce data integrity.
  • Inefficient Hierarchy Design: If your organization has a hierarchical structure, designing an inefficient hierarchy can impact data retrieval and reporting. Carefully consider the relationships between objects and the depth of the hierarchy.

10. Lack of Documentation:

Lack of documentation in Salesforce can lead to a variety of negative consequences, including:

  • Increased development and maintenance costs: Without proper documentation, developers may struggle to understand the system's functionality and make changes, leading to increased development time and costs.
  • Knowledge transfer challenges: When documentation is lacking, it can be difficult to transfer knowledge about the system to new team members or consultants, leading to delays and errors.
  • Reduced system reliability: Poor documentation can increase the risk of errors and bugs, as developers may not fully understand the system's dependencies and interactions.
  • Difficulty troubleshooting issues: When documentation is missing or outdated, it can be challenging to identify and resolve problems, leading to increased downtime and frustration.
  • Non-compliance with regulations: In industries with strict regulatory requirements, lack of documentation can make it difficult to demonstrate compliance and may lead to legal or financial penalties.
  • Increased risk of data loss: Without proper documentation, it may be difficult to recover data in the event of a system failure or security breach.

To mitigate these risks, it is essential to maintain comprehensive and up-to-date documentation for all Salesforce systems. This documentation should include information on system architecture, data models, workflows, processes, and user procedures.

11. Hardcoding of IDs:

Hardcoding IDs in Salesforce is generally considered a bad practice due to the following reasons:

  • Lack of flexibility: Hardcoded IDs make it difficult to modify or reuse components, as any changes require updating the hardcoded values.
  • Increased maintenance: Maintaining hardcoded IDs can be time-consuming and error-prone, especially in large or complex applications.
  • Reduced portability: Hardcoded IDs can make it difficult to transport or deploy applications between different environments.
  • Security risks: Hardcoded IDs can potentially expose sensitive information, such as API keys or user credentials.

Instead of hardcoding IDs, Salesforce provides several alternative approaches that are considered best practices:

  • Using Apex variables: Store IDs in Apex variables and reference them dynamically. This allows for greater flexibility and maintainability.
  • Using custom settings: Store IDs in custom settings to centralize configuration and make them easily accessible across the application.
  • Using formulas: Use formulas to dynamically reference IDs based on other field values.
  • Using SOQL queries: Query for IDs based on specific criteria using SOQL.
Anupam Tripathi
Anupam Tripathi

Anupam possesses over 17.5 years of comprehensive industry experience in the CRM domain. He holds 20 Salesforce certifications and is certified in Copado. He is adept at business analysis, architectural design, customization, administration, deployment, and the management of end-to-end Salesforce projects. He has executed over 16 projects for small and mid-sized businesses, which included rapid development initiatives, as well as five comprehensive implementations that utilized Service Cloud, Sales Cloud, Community Cloud, Force.com, and Marketing Cloud solutions.

Related reads.

WHAT WE DO.

Explore our wide gamut of digital transformation capabilities and our work across industries.

Explore