How is Aggregate Code Coverage Calculated in Salesforce?

Question

How does Salesforce calculate aggregate code coverage when multiple Apex classes are involved? Is it based on the average coverage per class or the ratio of covered lines to total testable lines?

Answer

Salesforce determines aggregate code coverage using the ratio of all covered lines to the total testable lines in the org, not by averaging the coverage percentages of individual classes. The formula used is:

Total Covered Lines / Total Testable Lines

For example, if there are two classes:

Class 1: 400 testable lines, 200 covered (200/400 = 50%)

Class 2: 10 testable lines, 10 covered (10/10 = 100%)

Using the incorrect approach of averaging class percentages:

(50% + 100%) / 2 = 75%

Since 51.2% is below the required 75%, deployment would not be allowed.

This method would falsely suggest the codebase meets Salesforce’s 75% minimum requirement, but this is not how Salesforce calculates coverage.

Instead, Salesforce uses the correct approach, which is the overall ratio of covered lines:

(200 + 10) / (400 + 10) = 210 / 410 = 51.2%

Since 51.2% is below the required 75%, deployment would not be allowed.

Explanation:

Salesforce enforces code coverage at the org level, meaning every testable line in every class contributes to the final percentage. A small class with 100% coverage has little impact compared to a large class with low coverage.

If you need to increase overall coverage, focusing on larger classes is usually more effective because adding coverage to a small class may have a negligible effect on the total ratio.

Real-Time Project-Based Salesforce Training to Kick Start Your Career

Our Salesforce course is designed to provide a comprehensive understanding of the Salesforce platform, equipping you with the essential skills to excel in the CRM industry. The curriculum covers key modules like Salesforce Admin, Developer, and AI, blending theoretical learning with hands-on practice. Through real-world projects and interactive exercises, you will gain the expertise needed to tackle business challenges using Salesforce solutions. Our experienced instructors ensure you develop both technical proficiency and industry-relevant insights to thrive in the Salesforce ecosystem.

Beyond technical training, our Salesforce training in Chennai offers personalized mentorship, certification guidance, and interview preparation to enhance your career prospects. You’ll have access to extensive study materials, hands-on project experience, and continuous support throughout your learning journey. By the end of the course, you’ll be fully prepared for certification exams and equipped with real-world problem-solving skills that employers seek. Take the first step toward your Salesforce career today—Enroll in a Free Demo now!

0
Would love your thoughts, please comment.x
()
x