Apex Code Character Limit (Part II)

Increase Apex Code Character Limit

We all know about Salesforce Apex Code Character limit and how to check the limit that we exhausted in our org. 

USE CASE:- For suppose, if I reached the maximum code character limit in my org and I would like to code further, but the system is not allowing me to do so. In this situation, can I reach out to Salesforce Support to get this limit increased for me?
  • The answer is YES. But conditions apply.
  • Increasing the Apex Code Character Limit is not an easy task for Salesforce support. We need to ensure that we followed all best practices and need to check for any anti-patterns, Invalid test practices and Invalid classes.
  • After performing all these checks from our end, then we are good to raise a case with Salesforce to increase the code character limit for my org.

Points to Note:-

  • The Code character limit count includes the spaces, tabs and other formatting characters inside the code.
  • The code comes with any managed package does not count against this code character limit. Because the managed package code belongs to a unique namespace and it is independent from your org's namespace.
  • This code character limit does not apply to any class that was annotated with @isTest at the beginning. Because, this would be considered as a test class and these test classes does not count against the Org's defined limit.

How to check for invalid Test patterns?

We can run a simple code snippet to analyze the test classes that aren't annotated correctly.

Integer totalchar=0;  
for(ApexClass a: [Select Id, Name, Body from ApexClass]) 
if(a.body.containsIgnoreCase('testmethod') && !a.body.containsIgnoreCase('@isTest')){ 
system.debug(a.Id + ' ' + a.name + ' ' + a.body.length()); 
totalchar = totalchar + a.body.length(); 
} } System.debug(totalchar); 

 The above mentioned code snippet provides you the count of test classes that were not annotated properly in the org. Ideally the result should be ZERO. This means that we wrote our test classes with correct annotations.


How to check for invalid Apex Classes?

We need to make sure that we write only valid apex classes. The best practice is to use the "isValid" flag while writing any apex class.
  • If we are not sure that all our apex class are valid ones or not. Then we can have the option to recompile all apex classes and run some SOQL queries to find the invalid classes.
  • In order to recompile all apex classes, Go to Setup --> Apex Classes --> Compile All classes. This will give us the correct code utilization.
  • And we can run some SOQL queries to find the invalid classes.
Select count() from ApexClass where isValid = false 
Select Id, Name from ApexClass where isValid = false 
  • The above mentioned queries will give us the count of invalid classes and we can even get those ID's and can delete those classes.

Can we raise a case with Salesforce support for code character increase?

Absolutely YES.

We can raise a case with Salesforce support with these mentioned details,
  1. Provide them the summary of the above mentioned details.
  2. Why you are looking for an increase to this limit.
  3. What is your current limit?
  4. What is your requested limit?
NOTE:-  Please do note that Salesforce will increase our code from 6 Million up to 10 Million characters, only if we followed the above mentioned best practices.
  • If we are looking for an increase beyond 10 Million characters, then it might be a difficult scenario where it required additional scrutiny from support.
  • All Salesforce editions are eligible for this code character limit increase except Professional Edition.

That's all Folks! Happy Learning!

Comments

Popular posts from this blog

Apex Code Character Limit (Part I)

SFDX Developer Guide

Deployment in Salesforce using Change sets

Force.com ANT Migration tool