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

How to pass parameters to system.currentPagereference.getParameters().get() in Test Methods

I have written the below code in the controller.

public void init()

While writing test methods i am not able to pass the parameters.Its showing code does'nt have test coverage

Any help will be appreciated.

Thanks in advance.
Best Answer chosen by Admin (Salesforce Developers) 

In testing, you want to build all new records (which are automatically deleted after the test is executed)

So, following your example, create the billTo account record, which creates its id.

Account billTo = new Account(
    name = 'BillTo');
insert billTo;

Then you create the controller and visual page in test

// Test MyController controller
PageReference pageRef = Page.MyPage;

// Add parameters to page URL
MyController myController = new MyController();

There is an example of this in the VisualForce documentation.