Activity Forums Salesforce® Discussions How to cover apexpages.currentpage().getparameters().get('id') in test class?

  • How to cover apexpages.currentpage().getparameters().get('id') in test class?

    Posted by Shweta on June 12, 2020 at 4:22 pm

    How to cover apexpages.currentpage().getparameters().get('id') in test class?

    Anuj replied 4 years, 5 months ago 2 Members · 1 Reply
  • 1 Reply
  • Anuj

    Member
    June 16, 2020 at 12:46 pm

    you can use this code....

    @isTest
    public class ExtensionTestClass
    {
    static testMethod void testMethod1()
    {
    Account testAccount = new Account();
    testAccount.Name='Test Account' ;
    insert testAccount;
    Test.StartTest();
    ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
    myControllerExtension testAccPlan = new myControllerExtension(sc);
    PageReference pageRef = Page.AccountPlan; // Add your VF page Name here
    pageRef.getParameters().put('id', String.valueOf(testAccount.Id));
    Test.setCurrentPage(pageRef);
    //testAccPlan.save(); call all your function here
    Test.StopTest();
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos