Sunday, June 14, 2020

Apex Percent Usage

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.

Salesforce allows you to increase limit upto 10,000,000 characters (10MB) on logging a case.

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.

public class test{
public String firstVar;
public String secondVar;
}
view raw FirstClass.java hosted with ❤ by GitHub
  • Adding redundant new lines (/n) in the code doesn't impact the usage.
public class test{
public String firstVar;
public String secondVar;
}
view raw newLines.java hosted with ❤ by GitHub
  • Adding redundant spaces/tab in between the code increases the usage.
public class test{
public String firstVar;
public String secondVar;
}
view raw withSpace.java hosted with ❤ by GitHub
  • Adding redundant spaces/tab even at the end of line increases the usage.
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)
public class test{
public String firstVar;
public String secondVar;
}
  • Adding comments in class don't impact the usage.

// 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.

@istest
private class testClass{
@isTest static void testName() {
Account a = new Account(name='test Account');
insert a;
}
}
view raw testClass.java hosted with ❤ by GitHub
  • Blank lines containing only spaces are also not counted towards the usage.

public class test{
public String firstVar;
public String secondVar;
}
Note : Managed packages are not counted towards the limit as they belong to different namespace as that of your org.

Thanks for reading.

If you liked the post do support me by buying a pizza for me :D


No comments:

Post a Comment