+ Start a Discussion
JessyJessy 

need a Unit Test Code for redirectextension

public with sharing class OpportunityRedirectExtension {
private ApexPages.StandardController controller = null;
public OpportunityRedirectExtension (ApexPages.StandardController controller){
this.controller = controller; }
public PageReference redirect(){
String prefix = Opportunity.sObjectType.getDescribe().getKeyPrefix();
String param = getParameters() ;
return new PageReference('/'+prefix+'/e?nooverride=1&'+param);


}

// Inherit previous parameters, more imporatntly, RecordType parameter!
private String getParameters(){ string param = '';
Map<String, String> strMap = ApexPages.currentPage().getParameters();
String[] keys = new String[]{'RecordType', 'retURL', 'cancelURL'};
for(String s : keys){
if(strMap.containsKey(S))
param += s + '=' + strMap.get(s) + '&';
}
if(param.length() > 0) param = param.substring(0, param.length()-1);
return param; }

}