• adeetz54724
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am trying to get code coverage for the class below:
public class redirectToWebinarPageController{
    public pageReference redirectURL(){
        
        //get the external id from the URL
        String externalId = ApexPages.currentPage().getParameters().get('externalId');
        
        //query the record.
        Webinar__c webinarRecord = [select id from Webinar__c where Webinar_Count__c =: externalId];
        
        //redirect to detail page of the above record.
        return new pageReference('/'+webinarRecord.id);
       
    }
}
Here is the test I have and am getting 75% coverage but I would prefer to know how to get 100%
@isTest 
public class redirectToWebinarPageControllerTest {
    public static testMethod void testredirectURL() {
        test.startTest();
        PageReference pageRef = Page.redirectToWebinarDetailPage;
        
        //Your test data logics
        Account testAccount = new Account();
        testAccount.Name = 'Account Name';
        insert testAccount;
        
        Contact testContact = new Contact();
        testContact.LastName = 'Contact';
        testContact.FirstName = 'Test';
        testContact.Email = 'testContact@testing.com';
        insert testContact;
        
        Webinar__c w = new Webinar__c();
        w.Name = 'Test Webinar';
        w.Account__c = testAccount.id;
        w.Communication_Type__c = 'Client 4';
        w.Delivery_Method__c = 'Self Study';
        w.Contact__c = testContact.id;
        insert w;
        
        String testExternalId = w.Webinar_Count__c;

        Test.setCurrentPage(pageRef);
			
			pageRef.getParameters().put('externalId',testExternalId);
			
			redirectToWebinarPageController controller = new redirectToWebinarPageController();
			controller.redirectURL();
        
   		test.stopTest();
     }
}
Thank you in advance, I am really new to writing test classes and would love to know what I am missing here.
I am trying to get code coverage for the class below:
public class redirectToWebinarPageController{
    public pageReference redirectURL(){
        
        //get the external id from the URL
        String externalId = ApexPages.currentPage().getParameters().get('externalId');
        
        //query the record.
        Webinar__c webinarRecord = [select id from Webinar__c where Webinar_Count__c =: externalId];
        
        //redirect to detail page of the above record.
        return new pageReference('/'+webinarRecord.id);
       
    }
}
Here is the test I have and am getting 75% coverage but I would prefer to know how to get 100%
@isTest 
public class redirectToWebinarPageControllerTest {
    public static testMethod void testredirectURL() {
        test.startTest();
        PageReference pageRef = Page.redirectToWebinarDetailPage;
        
        //Your test data logics
        Account testAccount = new Account();
        testAccount.Name = 'Account Name';
        insert testAccount;
        
        Contact testContact = new Contact();
        testContact.LastName = 'Contact';
        testContact.FirstName = 'Test';
        testContact.Email = 'testContact@testing.com';
        insert testContact;
        
        Webinar__c w = new Webinar__c();
        w.Name = 'Test Webinar';
        w.Account__c = testAccount.id;
        w.Communication_Type__c = 'Client 4';
        w.Delivery_Method__c = 'Self Study';
        w.Contact__c = testContact.id;
        insert w;
        
        String testExternalId = w.Webinar_Count__c;

        Test.setCurrentPage(pageRef);
			
			pageRef.getParameters().put('externalId',testExternalId);
			
			redirectToWebinarPageController controller = new redirectToWebinarPageController();
			controller.redirectURL();
        
   		test.stopTest();
     }
}
Thank you in advance, I am really new to writing test classes and would love to know what I am missing here.