In my constructor I'm declaring as

pagenm = ApexPages.currentPage().getUrl().substringbetween('apex/','?'); 

And in the action button I'm writing these lines

if(pagenm = 'Page1'){
   // some code here
}else if(pagenm = 'Page2'){
  // some code here

Now I need to cover these lines in Apex class.I'm getting

System.NullPointerException: Attempt to de-reference a null object

at pagenm in constructor. How should I put the url in test class.


In Test Class you need to set the current page and put the parameters that you want in the url.

For e.g.

   PageReference myVfPage = Page.YOUR_VF_PAGE;

   String id = ApexPages.currentPage().getParameters().get('id');

In above case add the parameter that you require in your code to successfully execute the business logic

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.