You need to sign in to do that
Don't have an account?
How to test a method that uses ApexPages.currentPage().getHeaders().get('Referer')
When a Visualforce Page1 calls Visualforce Page2 and Visualforce Page2 has a extension to an Apex class with a constructor that contains the following line of code
"ApexPages.currentPage().getHeaders().get('Referer')"
How can the class be tested when being called by a Apex test class instead of a Visualforce page?
The result of "ApexPages.currentPage().getHeaders().get('Referer')" is setting a class property that is being used by other methods of the class.
//*****************************************************
public class Payment_Extension
{
private Payment__c payment;
private ApexPages.StandardSetController myController;
private Payment currentPayment;
private boolean isReceivable;
//********************************************************************************
public Payment_Extension(ApexPages.StandardSetController stdController)
{
system.debug('PaymentReceivable_Extension');
payment = (Payment__c)stdController.getRecord();
myController = stdController;
isReceivable = ApexPages.currentPage().getHeaders().get('Referer').contains('tabspayreceivable');
}
//********************************************************************************
public List<selectOption> getReceivableTypes()
{
if(isReceivable)
{
return currentPayment.ReceivableTypes();
}
else
{
return currentPayment.PayableTypes();
}
}
}
//*****************************************************
You should just be able to put a value into the headers map:
All Answers
You should just be able to put a value into the headers map:
Any idea why I can't set a header in a pagereference that can be captured by another page, i.e.:
public PageReference redirect(){
Apexpages.Pagereference kbhome = new Apexpages.pagereference('/apex/refererredirect');
kbhome.getHeaders().put('SomeHeader','SomeValue');
kbhome.setRedirect(true);
return kbhome;
}
The header doesn't show up in the other VF page.
Thanks
Hi
Can you please give a example on how and where to use setHeader method?
I tried the same stuff using getHeaders but I am always getting the error on the below link:
http://boards.developerforce.com/t5/Apex-Code-Development/Cyclical-server-side-forwards-detected-Did-anyone-face-this-APEX/td-p/504167
Any help on this is appreciated!