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
SFineSFine 

ApexPages.currentPage().getParameters().put() Not passing information?

Hello, a strange bug for me came up just about an hour ago, involving the ApexPages.currentPage().getParameters().put(); feature.

 

I keep getting a nullpointer exception: de-referencing a null object. And It's narrowed down to this particular line. Here's some sample test code where it occurs

 

 

  Quote opp=[select Id from Quote limit 1];

  QuoteLineItem ql1 = new QuoteLineItem();
  QuoteLineItem ql2 = new QuoteLineItem();
  PricebookEntry CL = [Select Product2.Name, Product2.Family, UnitPrice from PricebookEntry Where Product2.Family='Power' limit 1];
  PricebookEntry ST = [Select Product2.Name, Product2.Family, UnitPrice from PricebookEntry Where Product2.Family='Systems' limit 1];
  
  ql1.PricebookEntryId=CL.Id;
  ql1.Quantity=1;
  ql1.UnitPrice=CL.UnitPrice;
  ql1.QuoteId=opp.Id;
  insert ql1;
  
  ql2.PricebookEntryId=ST.Id;
  ql2.QuoteId=opp.Id;
  ql2.UnitPrice=ST.UnitPrice; 
  ql2.Quantity=1;
  insert ql2;
  
  PageReference pageRef = Page.quotePDF;
  Test.setCurrentPage(pageRef);
  ApexPages.currentPage().getParameters().put('Id', opp.id);
  //quotePDFController qc= new quotePDFController(ApexPages.StandardController(q));
  quotePDFController qc= new quotePDFController();

 

 

Any idea what's happening? Considering that it just randomly began to happen, I'm ver confused.

*werewolf**werewolf*

Rather than setting the current reference and then getting it again, perhaps you'd be better off doing something like

 

PageReference pageRef = Page.quotePDF;
pageRef.getParameters().put('Id', opp.id);
Test.setCurrentPage(pageRef);
Amar cAmar c

Thanks you saved my time :)