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
AUCTUS AdministratorAUCTUS Administrator 

Problem while encoding string to url standards for URL Hack

Hi eversyone, 

short description of what I am aiming to achieve: 
I have a Flow which has a variable (or more if I get it to work). This flow is rendered in a Visualforce Page controlled by a controller I wrote.
I want the Users to run the Flow over a Link, select multiple multipicklist values and then to click on finish. Then they should be redirected to a report with an URL Hack. The Variable of the Flow whould then be one of the criterias of the report filter.

If they select: BnB Manager and Specialist 
The output of the field looks like: BnB Manager, Specialist 
In the Controller I want to get: BnB%20Manager%2C%20Specialist. 

This is the VFP:
<apex:page controller="ExpertflowController" showHeader="true" standardStylesheets="true" language="de"> 
                             <flow:interview name="ExpertQueue" interview="{!ExpertInterview}" finishLocation="{!prFinishLocation}" />                                                                               
 </apex:page>
And the controller:
 
public class ExpertflowController{
public Flow.Interview.ExpertQueue ExpertInterview {get;set;}
public PageReference prFinishLocation {
 get {
PageReference prRef = new PageReference('/00O240000048JoX?pv0=' + strOutputVariable); prRef.setRedirect(true);
 return prRef;
 }
 set { prFinishLocation = value; }
 }
public String strOutputVariable {
 get {
 String strTemp = '';
 if(ExpertInterview != null) {
 strTemp = string.valueOf(ExpertInterview.Input);
 }
 return strTemp;
 }
 set { strOutputVariable = value; }
 }
}


Whenever I use the strTemp = strTemp.replaceAll('\\s+', '%20');

I can safe the controller, but I get this error while running the VFP:

Attempt to de-reference a null object 
Ein unerwarteter Fehler ist aufgetreten. Ihre Entwicklungsorganisation wurde benachrichtigt.

 
Many thanks in advance :) and wishing you all a merry christmas time. 

Best

Sam

 
Best Answer chosen by AUCTUS Administrator
AUCTUS AdministratorAUCTUS Administrator
In case someone is interested in a solution - this finaly worked: 
 
public class ExpertflowController{
public Flow.Interview.ExpertQueue ExpertInterview {get;set;}
public PageReference prFinishLocation {
 get {
PageReference prRef = new PageReference('https://auctus.my.salesforce.com/00O240000048JoX?pv0=' + EncodingUtil.urlEncode(strOutputVariable,'UTF-8')); 
prRef.setRedirect(true);
 return prRef;
 }
 set { prFinishLocation = value; }
 }
public String InterVar {
 get {
 String strTemp = '';
 if(ExpertInterview != null) {
 strTemp = string.valueOf(ExpertInterview.FunctionInput);
 }
 return strTemp;
 }
 set { InterVar = value; }
 }
 public String strOutputVariable {
 get {
 String NewVar = '';
 if( Intervar != null) {
 NewVar = string.valueOf(InterVar.replaceAll(';',','));
 System.Debug(NewVar);
 }
 return NewVar;
 } 
 set { strOutputVariable = value; }
 }
}

All Answers

AUCTUS AdministratorAUCTUS Administrator
public class ExpertflowController{
public Flow.Interview.ExpertQueue ExpertInterview {get;set;}
public PageReference prFinishLocation {
 get {
PageReference prRef = new PageReference('/00O240000048JoX?pv0=' + strOutputVariable); prRef.setRedirect(true);
 return prRef;
 }
 set { prFinishLocation = value; }
 }
 
 public string umweg {
 get {
 String strTemp = '';
 if(ExpertInterview != null) {
 strTemp = string.valueOf(ExpertInterview.Input);
 }
 return strTemp;
 }
 set { umweg = value;}
 }
 
public String strOutputVariable {
 get {
 String strTemp2 = umweg;
 strTemp2 = strTemp2.replaceAll('\\s+', '%20');
 System.Debug(strTemp2);
 return strTemp2;
 }
 set { strOutputVariable = value; }
 }
}
I read that I could not edit a string which is already set.. So I tried this but it keeps telling me I am still attempting to de-reference a null object.

Thanks for help.
AUCTUS AdministratorAUCTUS Administrator
I am very lost with this problem... I am so far by now: 
 
public class ExpertflowController{
public Flow.Interview.ExpertQueue ExpertInterview {get;set;}
public PageReference prFinishLocation {
 get {
PageReference prRef = new PageReference('/00O240000048JoX?pv0=' + strOutputVariable); prRef.setRedirect(true);
 return prRef;
 }
 set { prFinishLocation = value; }
 }
public String InterVar {
 get {
 String strTemp = '';
 if(ExpertInterview != null) {
 strTemp = string.valueOf(ExpertInterview.Input);
 }
 return strTemp;
 }
 set { InterVar = value; }
 }
 
 public String strOutputVariable {
 get {
 String NewVar = '';
 if( Intervar != null) {
 NewVar = string.valueOf(InterVar.replaceAll('\\s+','%20'));
 System.Debug(NewVar);
 }
 return NewVar;
 } 
 set { strOutputVariable = value; }
 }
}
I still have hope, someone can tell me why its not working :(

At least I don't get any error message any more, but it does still not replace the blank spaces with "%20".
 
AUCTUS AdministratorAUCTUS Administrator
In case someone is interested in a solution - this finaly worked: 
 
public class ExpertflowController{
public Flow.Interview.ExpertQueue ExpertInterview {get;set;}
public PageReference prFinishLocation {
 get {
PageReference prRef = new PageReference('https://auctus.my.salesforce.com/00O240000048JoX?pv0=' + EncodingUtil.urlEncode(strOutputVariable,'UTF-8')); 
prRef.setRedirect(true);
 return prRef;
 }
 set { prFinishLocation = value; }
 }
public String InterVar {
 get {
 String strTemp = '';
 if(ExpertInterview != null) {
 strTemp = string.valueOf(ExpertInterview.FunctionInput);
 }
 return strTemp;
 }
 set { InterVar = value; }
 }
 public String strOutputVariable {
 get {
 String NewVar = '';
 if( Intervar != null) {
 NewVar = string.valueOf(InterVar.replaceAll(';',','));
 System.Debug(NewVar);
 }
 return NewVar;
 } 
 set { strOutputVariable = value; }
 }
}
This was selected as the best answer