Salesforce’s cloud platform (force.com) provides a lot of flexibility for customizations, with Apex code being the most common way to develop new functionalities on the platform. However, unlike development stacks like Java and .Net, there are limits imposed by the shared force.com platform. This is to ensure that no single customer takes up too many computing resources, and hence there are limits on the amount of Apex code as well. As customers continue developing new customizations using Apex, it is likely that they will start reaching the code limit at some point in time.

apexcodelimit-cartoon

Before we dive into details around Apex code limits, let us understand the best practices for building applications on the force.com platform. Architects and developers should always check if the functionality that users have requested already exists in a professional, well-constructed appexchange package. That should almost always be the first option considered before going down the path of custom development. If there are no appropriate products available, we also need to evaluate if the functionality is well suited for development on the force.com platform. For the purpose of this article, we will assume scenarios where complex customizations are required on the force.com platform, which in turn requires us to better understand Apex code limits.

According to currently available documentation from Salesforce[1], the percentage of Apex code calculated for an org is the total number of characters of all apex classes and triggers divided by the total character limit of 3,000,000, expressed as a percentage. For e.g., if the total characters used in an org is at 1,500,000, the org would have reached 50% of it’s Apex code limit.

Some key points to note about the computation of this count:

  • The character count includes spaces, tabs and other formatting characters
  • Any code in a class defined with @isTest annotation (test class), and any commented lines in a class or trigger are not counted against this limit
  • Apex code in installed managed packages are not counted against this limit

Now that we understand the calculations done by Salesforce, let’s look into the options available to avoid reaching these limits.

While avoiding extra spaces and unnecessary tabs seems like a possible option, we expect that most (reasonable!) developers would not use a high number of those characters to make it a significant item. Well indented, readable code is a highly regarded software engineering best practice, and developers need to ensure that they follow it to an optimal level.

Salesforce can also increase Apex code limits if clients request an increase. However, before increasing this limit, Salesforce typically conducts a review process. Clients will have to justify the need to increase this limit, and also show what efforts they have taken in refactoring their code. While Salesforce will, under justified conditions, increase this limit, clients should recognize some lurking pitfalls. More lines of code also means there is more code to test and maintain, and also increases the dependence on adequate trained staff to support this custom code.

The last option is to leverage the concept of managed packages since they do not count against code limits. This method is similar to how appexchange packages work, and requires a good understanding of the force.com platform, and it’s code migration and deployment options. Developers can migrate code in a modular fashion into private managed packages which can then be deployed into their orgs. This may offer a very clean approach to the problem of code limits, and even offer other benefits to managing your org, but is a fairly complex process that should be handled by experienced developers with a lot of care.

In summary, to avoid  running into Salesforce’s Apex code limits,  customers can follow the steps given below:

  1. Evaluate appexchange packages to avoid custom development
  2. Where custom development is required, develop modular, optimizated code
  3. Consider using managed packages to avoid running into apex code limits
  4. As a temporary measure, contact Salesforce to increase apex code limits

 

SPAR Solutions has experience developing and managing complex applications and integrations, including managed packages on the force.com platform. Our team is available to help you with any questions or challenges you may be facing with your current implementation.

Like to have us contact you? Click here