Tuesday, 22 March 2016

URL Parameters in to Detail Page Custom Button Java script

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.