function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Binu 8Binu 8 

Showing Code Coverage Failure

HI Team,

I am new to salesforce. When I am trying to move my change sets from sandbox to production Code Coverage Failure is showing.
I have a Apex controller and visual force page in sandbox. Apex class have only one method which is return an agregate result of a custom object.
And I am showing some dashboard in VF page using these results. How can I write test cases for this one method and improve code coverage?
Could you please give a better suggestions to improve the code coverage or any examples?
Best Answer chosen by Binu 8
KaranrajKaranraj
Yes you have include testclass and other dependent componenets in your changeset.Run the test class in sandbox instance developer console and check the codecoverage of your apex class. Your test class coverage should be above 75% else you will get an error while deploying your components. Minimum code coverage should be 75% so always try to keep it above 90% coverage for your apex class.
 

All Answers

KaranrajKaranraj
Binu - Check this Apex Testing Trailhead module which helps you to understand how to write test class in salesforce - https://developer.salesforce.com/trailhead/apex_testing
Binu 8Binu 8
Hi karan,

The page does not exist..could you please check?
Binu 8Binu 8
Hi Karan

I wrote a test class like this.And executed the test.It is completed with no error. And after that I uploaded the change sets to production.But In production the same error is showng.I did not upload the test class file.I think I missed it to upload the test class.Is that right?

@isTest
public class SubscriptionReportTest {
    
    @isTest static void testSubscriptionData(){
        LIST<AggregateResult> slist = SubscriptionReportController.getSubscriptionData(2015);
        System.debug(slist);
        System.assert(true);
        
        LIST<AggregateResult> slist1 = SubscriptionReportController.getSubscriptionData(2014);
        System.assert(true);
        
    }
}
KaranrajKaranraj
Yes you have include testclass and other dependent componenets in your changeset.Run the test class in sandbox instance developer console and check the codecoverage of your apex class. Your test class coverage should be above 75% else you will get an error while deploying your components. Minimum code coverage should be 75% so always try to keep it above 90% coverage for your apex class.
 
This was selected as the best answer
Binu 8Binu 8
Thanks karan..Its deployed in production...thanks a lot