I wanted to check on how is Apex code counted towards the limit, considering we are only allowed 6,000,000 characters (6 MB ) and we might come across a situation where we may want to increase the aforementioned limit.



Note : Managed packages are not counted towards the limit as they belong to different namespace as that of your org.
Thanks for reading.
Salesforce allows you to increase limit upto 10,000,000 characters (10MB) on logging a case.
Salesforce doc
Salesforce doc
I have created a few scenarios to check on what all simple things contribute towards this usage.
After creating a dummy class below is apex usage, we would run different scenarios on below class to see how is apex usage changed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class test{ | |
public String firstVar; | |
public String secondVar; | |
} |
- Adding redundant new lines (/n) in the code doesn't impact the usage.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class test{ | |
public String firstVar; | |
public String secondVar; | |
} |
- Adding redundant spaces/tab in between the code increases the usage.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class test{ | |
public String firstVar; | |
public String secondVar; | |
} |
- Adding redundant spaces/tab even at the end of line increases the usage.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class test{ | |
public String firstVar; | |
public String secondVar; | |
} |
- Adding spaces/tabs for indentation of code also seems to increase the usage(for demo purposes I have indented class variables only)

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class test{ | |
public String firstVar; | |
public String secondVar; | |
} |
- Adding comments in class don't impact the usage.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the dummy class I have created to check Apex usage | |
public class test{ | |
// first variable | |
public String firstVar; | |
// second variable | |
public String secondVar; | |
// end of variables | |
} |
- Creating a test class don't count towards apex usage ie redundant tabs/spaces none of them are counted.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@istest | |
private class testClass{ | |
@isTest static void testName() { | |
Account a = new Account(name='test Account'); | |
insert a; | |
} | |
} |
- Blank lines containing only spaces are also not counted towards the usage.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class test{ | |
public String firstVar; | |
public String secondVar; | |
} |
Thanks for reading.