Hi,
We have below different methods to capture the URL methods in Apex and Visual force pages,
Apex Class :
apexpages.currentpage().getparameters().get('id')
Visual force Page :
{!$currentpage.parameters.Id}
But in the case of Detail Page Custom Button Java script , above methods will not work , In this we need to handle in the Java script and get the intended parameters from URL .
Here is the script to get URL parameters ,
function GetURLParam(){
var ReturnURL = '';
var sURL = window.location.href;
if (sURL.indexOf("?") > 0){
var arrParams = sURL.split("?");
var arrURLParams = arrParams[1].split("&");
var arrParamNames = new Array(arrURLParams.length);
var arrParamValues = new Array(arrURLParams.length);
var i = 0;
for (i = 0; i<arrURLParams.length; i++){
var sParam = arrURLParams[i].split("=");
arrParamNames[i] = sParam[0];
if (sParam[1] != "")
arrParamValues[i] = unescape(sParam[1]);
else
arrParamValues[i] = "No Value";
}
for (i=0; i<arrURLParams.length; i++){
if (arrParamNames[i] == 'retURL'){
ReturnURL = arrParamValues[i];
}
}
}
}
Thank you.
We have below different methods to capture the URL methods in Apex and Visual force pages,
Apex Class :
apexpages.currentpage().getparameters().get('id')
Visual force Page :
{!$currentpage.parameters.Id}
But in the case of Detail Page Custom Button Java script , above methods will not work , In this we need to handle in the Java script and get the intended parameters from URL .
Here is the script to get URL parameters ,
function GetURLParam(){
var ReturnURL = '';
var sURL = window.location.href;
if (sURL.indexOf("?") > 0){
var arrParams = sURL.split("?");
var arrURLParams = arrParams[1].split("&");
var arrParamNames = new Array(arrURLParams.length);
var arrParamValues = new Array(arrURLParams.length);
var i = 0;
for (i = 0; i<arrURLParams.length; i++){
var sParam = arrURLParams[i].split("=");
arrParamNames[i] = sParam[0];
if (sParam[1] != "")
arrParamValues[i] = unescape(sParam[1]);
else
arrParamValues[i] = "No Value";
}
for (i=0; i<arrURLParams.length; i++){
if (arrParamNames[i] == 'retURL'){
ReturnURL = arrParamValues[i];
}
}
}
}
Thank you.
Hi Hari,
ReplyDeleteYou have provided the code in script, you can get the detail in apex class as below:
pageReference currentPage = new pageReference(EncodingUtil.urlDecode(Apexpages.currentPage().getUrl(), 'UTF-8'));
String id_parameter = currentPage.getParameters().get('id');