Apex Custom Code Calculator

The Apx Custom Code Calculator application calculates the increased/decreased custom code percentage and length difference in your sandbox as compared to production org.

Why do WE need this application?

The maximum amount of code used by all Apex code in an org is 6 MB ( 6,000,000 characters) and Salesforce recommends not using too much code in an org. So companies/customers follow recommendation seriously and whenever a developer propose/implement the solution using apex code, the review team wants to know how much custom code percentage is going to increase due to this implementation, and based on that they accept or reject the solution.

Let’s check how the developer calculates the custom code percentage?

Following are the steps :
  • First, go to the developer sandbox and search for the apex class or trigger in which the developer added the code.
  • Copy the “Size Without Comments” column value from there and make a note of that value.
  • Now, go to production org and search for the same apex class or trigger.
  • Copy the “Size Without Comments” column value from production and take a note of that value.
  • Use calculator software, to calculate length difference and custom code percentage increased or decreased.
⚠️ Problems in the above steps:
  • The above steps/process is a little time-consuming.
  • We don’t have a quick search to find apex class or trigger.
  • Need to navigate through long pagination for some cases to find the apex class/trigger “Size Without Comments” value.
  • Calculations need to be done manually on calculator software.
  • Chance of error in the calculations.

All the above problems you can solve using this application.

🔆 Features
  • Quickly search Apex class or trigger right inside your sandbox org.
  • This app tells you the apex class/trigger length in the developer sandbox.
  • This calculates the length difference and custom code percentage increased /decreased in just a single click.
  • If you have created a new class or trigger, then also it will calculate the custom code percentage for you.
  • We can only search for the classes that we have created; it excludes the managed package classes in the search.
  • Nice and easy interface developed with a lighting web component.
( (length In Source Org - length In Destination Org) * 100 ) / 6000000


📦 Click Here to install the package in the Sandbox instance.

or use the below URL:

🔗 https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5j000000giuh

🛠️ Setup & Configurations

Create a connected app in the Production instance.

  • Go to setup and search ‘connected app’ in the quick find box. Click on ‘Manage Connected Apps’.
  • Click on the new button.
  • Fill the required field as shown on the screen below and click on save.

Create an Auth. provider in the sandbox instance.

Copy the callback URL after saving and take a note of that. We need to put this callback URL in the connected app created in the production instance. Go to the production org and open the connected app. Click on the edit button and enter the callback URL. Click Save.

Note: The applied changes in the connected app may take up to 10 min so test the application after 10 min if you have made the changes in the connected app.

Create a Named Credential in the sandbox instance.

  • Go to setup, search ‘Named Credential’ in the quick find box and click on Named Credentials.
  • Click on the new button.
  • In the URL field enter your production instance base URL.
  • Check the checkbox “Start Authentication Flow on Save”.
  • Click on save. It will redirect to the login page and there you need to log in with your production user credentials.
  • On successful login, a page will appear, click on Allow button. After that, it will redirect back to the named credential record page.
  • Now click on save again.

Yay! setup & configuration steps are done!


Goto app launcher and select ‘Custom Code Calculator’.

You can find the application source code here on Github

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s