What is Salesforce concurrent limits?

Understanding Salesforce Concurrency Limits: A Comprehensive Guide

Quick answer
This page answers What is Salesforce concurrent limits? quickly.

Fast answer first. Then use the tabs or video for more detail.

  • Watch the video explanation below for a faster overview.
  • Game mechanics may change with updates or patches.
  • Use this block to get the short answer without scrolling the whole page.
  • Read the FAQ section if the article has one.
  • Use the table of contents to jump straight to the detailed section you need.
  • Watch the video first, then skim the article for specifics.

Salesforce concurrency limits define the maximum number of simultaneous processes that can run within a Salesforce organization (org) at any given time. These limits are put in place to maintain the stability, performance, and overall health of the Salesforce multi-tenant environment. Think of it like a highway – if too many cars try to use it at once, everything slows down or grinds to a halt. Salesforce uses concurrency limits to prevent any single organization from monopolizing resources and impacting the experience of others.

Without these limits, poorly designed or inefficient code could consume excessive resources, leading to performance degradation, errors, and even outages for all users within the shared Salesforce infrastructure. Understanding these limits and designing your applications to operate efficiently within them is crucial for building robust and scalable Salesforce solutions. These limits affect various aspects of your org, from API requests to Apex transactions and email sending.

Key Concurrency Limits in Salesforce

Let’s explore some of the most important concurrency limits that you need to be aware of:

  • Concurrent Long-Running Apex Limit: This limit restricts the number of long-running synchronous Apex transactions executing simultaneously in your org. Currently, only 10 synchronous transactions can execute for more than 5 seconds at any given time. Exceeding this limit can lead to Concurrent Apex Errors, which will prevent subsequent transactions from processing until existing long-running transactions complete.
  • Concurrent API Request Limit: Salesforce imposes limits on the number of simultaneous API requests that can be processed. The exact limit depends on your Salesforce edition and the type of API being used. Exceeding these limits results in API exceptions, preventing further API calls until the concurrency level drops below the allowed threshold.
  • Concurrent Batch Apex Limit: Salesforce limits the number of batch jobs that can run concurrently. Only five batch jobs can be queued or active concurrently. This prevents batch jobs from overwhelming the system and impacting the performance of other users.
  • Callout Limits: When Apex code makes callouts to external systems (HTTP requests or web services calls), Salesforce imposes limits on the number of callouts that can be made within a single transaction. A single Apex transaction can make a maximum of 100 callouts. The default timeout for a callout is typically 10 seconds.
  • Email Sending Limits: Each Salesforce org has a daily limit for sending single emails. This is capped at a maximum of 5,000 external email addresses per day based on Greenwich Mean Time (GMT). It’s worth noting that this limit applies to single emails and not to mass emails sent via Salesforce’s marketing tools.

Strategies for Avoiding Concurrency Limit Issues

To avoid hitting concurrency limits and ensure the smooth operation of your Salesforce applications, consider the following strategies:

  • Optimize Code: Write efficient and well-optimized code that minimizes resource consumption and execution time. Review your Apex code, SOQL queries, and triggers to identify areas for improvement. Pay special attention to avoiding nested loops, using bulkification techniques to process data in batches, and optimizing SOQL queries to return only the necessary data.
  • Asynchronous Processing: Offload long-running processes to asynchronous execution using techniques like Queueable Apex, Future Methods, and Batch Apex. Asynchronous processing allows you to defer the execution of resource-intensive tasks to a later time, reducing the load on the system during peak hours.
  • Governor Limits Awareness: Be acutely aware of all governor limits in Salesforce. Governor limits are runtime limits enforced by the Apex runtime engine. They are there to ensure that code does not throw errors and prevent any single Apex transaction from monopolizing shared resources. Monitor your code’s usage of resources and adjust your design accordingly.
  • Efficient SOQL Queries: Craft efficient SOQL queries with appropriate filtering and indexing to minimize the amount of data retrieved. Limit the fields returned in your queries to only what is needed, and avoid using wildcard queries that can lead to performance bottlenecks. Remember that while the TOTAL length of a SOQL query must be less than 20,000 characters, the WHERE clause can only be 4,000 characters.
  • Effective Error Handling: Implement robust error handling mechanisms to gracefully handle exceptions and prevent them from escalating into system-wide issues. Log errors and provide informative messages to users so they can take appropriate action.
  • Monitor Performance: Regularly monitor the performance of your Salesforce applications to identify potential bottlenecks and areas for improvement. Use Salesforce’s built-in monitoring tools and third-party solutions to track resource usage, identify slow-running queries, and detect potential concurrency issues. You can check your API Limit per Month by navigating to Company Information within Setup. The details can be seen under ‘Usage-Based Entitlements’.
  • Judicious Use of Callouts: Minimize the number of callouts made from Apex code, and ensure that callouts are handled efficiently. Use caching mechanisms to store frequently accessed data from external systems, and avoid making redundant callouts. Ensure your Apex code does not exceed the limit of 100 callouts in a single transaction.
  • Batch Processing: Use Batch Apex for processing large datasets, breaking the data into smaller batches that can be processed asynchronously. This approach prevents individual transactions from exceeding governor limits and improves overall system performance. Note that a maximum of five batch jobs can be submitted in case of a running test.
  • Testing and Optimization: Thoroughly test your code in a sandbox environment before deploying it to production. Use profiling tools to identify performance bottlenecks and optimize your code accordingly. Run load tests to simulate real-world usage scenarios and ensure that your applications can handle the expected volume of traffic without exceeding concurrency limits.
  • Stay Updated: Keep abreast of the latest Salesforce releases and best practices for performance optimization. Salesforce regularly introduces new features and enhancements that can help you improve the efficiency and scalability of your applications.

By understanding these concurrency limits and implementing the strategies outlined above, you can build robust and scalable Salesforce applications that deliver optimal performance and avoid the pitfalls of exceeding resource limits. Remember to prioritize code optimization, asynchronous processing, and efficient data handling to ensure a smooth and reliable user experience. Explore topics like game-based learning through the Games Learning Society at https://www.gameslearningsociety.org/, which promotes innovative problem-solving techniques applicable to optimizing code and managing system limitations.

Frequently Asked Questions (FAQs)

Here are some frequently asked questions regarding concurrency limits in Salesforce:

1. What happens when a concurrency limit is exceeded?

When a concurrency limit is exceeded, Salesforce will typically throw an exception or error message, preventing the offending transaction from completing. This can result in data loss, application errors, and a degraded user experience.

2. How can I check my org’s current API usage?

You can check your org’s current API usage by navigating to Setup > Company Settings > Company Information and looking under the ‘Usage-Based Entitlements’ section. This displays your API usage and remaining limits.

3. Are concurrency limits the same for all Salesforce editions?

No, concurrency limits vary depending on your Salesforce edition and contract. Enterprise Edition and Unlimited Edition typically have higher limits than Professional Edition and Group Edition.

4. How does the Concurrent Long Running Apex Limit impact my code?

The Concurrent Long Running Apex Limit restricts the number of synchronous Apex transactions that can run for more than 5 seconds. If you exceed this limit, subsequent transactions will be blocked until one or more of the long-running transactions completes. This can cause performance issues and delays in your application.

5. What is the difference between synchronous and asynchronous Apex?

Synchronous Apex executes immediately when triggered, while asynchronous Apex is queued for execution at a later time. Asynchronous Apex is ideal for long-running processes that don’t need to be executed immediately.

6. Can I increase my org’s concurrency limits?

In some cases, it may be possible to increase your org’s concurrency limits by contacting Salesforce support and requesting a quota increase. However, this typically requires a strong business justification and may involve additional costs. For AWS Lambda, you can request a concurrency increase through the Service Quotas dashboard.

7. What are governor limits, and how do they relate to concurrency limits?

Governor limits are runtime limits enforced by the Apex runtime engine to prevent code from monopolizing shared resources in the multi-tenant environment. Concurrency limits are a type of governor limit that restricts the number of simultaneous processes.

8. How many SOQL queries can I execute in a single transaction?

You can execute a maximum of 100 SOQL queries in a synchronous transaction and 200 SOQL queries in an asynchronous transaction. Additionally, remember the maximum number of rows returned per transaction is 50,000.

9. What are the best practices for optimizing SOQL queries?

Best practices for optimizing SOQL queries include using selective filters, avoiding wildcard queries, limiting the fields returned, and using indexes where appropriate. The WHERE clause can only be 4,000 characters.

10. How can I prevent Apex CPU time limit exceeded errors?

To prevent “Apex CPU time limit exceeded” errors, you should optimize your code, use asynchronous processing, bulkify your code, and avoid nested loops. Process manual inserts in smaller batches, schedule automation strategically, and control batch sizes.

11. What is the maximum batch size for Batch Apex?

The maximum batch size for Batch Apex is 2,000 records.

12. How does sharing records impact concurrency limits in Salesforce to Salesforce?

Salesforce to Salesforce allows record sharing, with a maximum of 100 tasks per related record. This limit includes both open and closed tasks.

13. What are future methods, and when should I use them?

Future methods are asynchronous methods that are annotated with @future. They are useful for performing long-running operations that don’t need to be executed immediately. Future methods have a limit of 50 calls per transaction and a maximum timeout of 60 seconds.

14. What is the maximum offset limit in SOQL?

The maximum offset limit is 2,000 rows. Requesting an offset greater than 2,000 will result in a NUMBER_OUTSIDE_VALID_RANGE error. Workarounds include using techniques that do not rely on offset.

15. What are Queueable Apex limits?

Queueable Apex offers improved limits compared to Future Methods. Queueable methods have higher execution limits, with the maximum timeout set at 60 minutes.

Understanding and managing Salesforce concurrency limits is crucial for building efficient and reliable applications. By adhering to best practices for code optimization, asynchronous processing, and data handling, you can ensure that your applications run smoothly and avoid the pitfalls of exceeding resource limits. Embrace ongoing learning and explore interdisciplinary fields, like game-based learning strategies taught at the GamesLearningSociety.org, to discover new and innovative ways to solve complex system challenges.

Leave a Comment