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
AdnanAdnan 

Apex Class to redirect a page.

Hi,

 

I have this class and am trying to deploy but getting error "Average test coverage across all Apex Classes and Triggers is 70%, at least 75% test coverage is required".

Below I am pasting my code. Any assistance is helpful

 

 

public class MigrationExtension {

    private final Lead migrationlead;

    public MigrationExtension(ApexPages.StandardController
                                stdController) {
       migrationlead = (Lead)stdController.getRecord();
    }

     public PageReference saveLead() {
       try {
       insert(migrationlead);
       }
       catch(System.DMLException e) {
           ApexPages.addMessages(e);
           return null;
       }
       PageReference p = Page.ThankMigration;
       p.setRedirect(true);
       return p;
     }

Best Answer chosen by Admin (Salesforce Developers) 
AdnanAdnan

I was able to create a Test extension for this and was able to bring both the Extension and Test Extension over.

 

Thanks

All Answers

ashish raiashish rai

Hello,

well dude you have to write the test method for this class. When ever you deploy your code your trigger and class code coverage must be more than all equal to 75%. I can write the test method here but want you to write this, so than in future you will know how to write this. So please go through the docs of how to write the test method. 

AdnanAdnan

Hi Ashish,

 

I am new to this, but I gave it a shot and still getting the error.

 

public class MigrationExtensionTest {
static testMethod void MigrationTest () {


 Lead testLead = new Lead();
        testLead.FirstName = 'Test FirstName';
          testLead.LastName = 'Test LastName';
          testLead.Company = 'Test Company';
          testLead.State = 'CA';
          testLead.PostalCode = '94133';
          testLead.Lead_Tactic__c = '';

    insert TestLead;

}
}
AdnanAdnan

I was able to create a Test extension for this and was able to bring both the Extension and Test Extension over.

 

Thanks

This was selected as the best answer