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
Peter BölkePeter Bölke 

Testing ApexPages.currentPage().getParameters()

Hello,

how can i test following snippet?
 
if(ApexPages.currentPage().getParameters().get('aID') != null)
{
tempID = ApexPages.currentPage().getParameters().get('aID');


}else{
tempID = ApexPages.currentPage().getParameters().values()[1];
}
It works fine with an AccounID,....but how can i test it with an ContactID or else?

Those line belong to custom controller extension für a file upload. This Upload can be accessed from any object in our saleforce environment. But mainly from Accounts.

thanks
Peter
 
Best Answer chosen by Peter Bölke
Waqar Hussain SFWaqar Hussain SF
Are you talking about test class?
If yes then you can use the following code in your test class
 
PageReference myVfPage = Page.YOUR_PAGE_NAME;
Test.setCurrentPage(myVfPage);

// Put Id into the current page Parameters
ApexPages.currentPage().getParameters().put('aID', ID_OF_RECORD);

Let me know If you have any question.
 

All Answers

Devanshu soodDevanshu sood

Its simple : pass the id value in URL like this 
 
 

 

apexpages.currentpage().getparameters().put('id' , yourID);
yourClass controller = new yourClass() ;
 

thanks
 

Waqar Hussain SFWaqar Hussain SF
Are you talking about test class?
If yes then you can use the following code in your test class
 
PageReference myVfPage = Page.YOUR_PAGE_NAME;
Test.setCurrentPage(myVfPage);

// Put Id into the current page Parameters
ApexPages.currentPage().getParameters().put('aID', ID_OF_RECORD);

Let me know If you have any question.
 
This was selected as the best answer