5

How to access the Id from URL in visualforce, i want to pass that Id to javascript function to load my page, please help.

3 Answers 3

6

You can access it vial $CurrentPage global variable avaialble in visualforce for e.g.

{!$CurrentPage.parameters.relatedId}

in JS

 var tempValue = '{!$CurrentPage.parameters.relatedId}';

For more details refer:- https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_currentpage.htm

2
  • Thanks Anshul, can you provice snippet how to pass this to javascript function. Thanks in Advance
    – user21059
    Commented Jun 5, 2015 at 5:56
  • 2
    you can simply assign it to a javascript variable var tempValue = '{!$CurrentPage.parameters.relatedId}';
    – Anshul
    Commented Jun 5, 2015 at 6:12
2
function getUrlParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
} 

/apex/test?id=1
var id = getUrlParameter('id');
2

Use can access URL parameters directly in VF page using $CurrentPage global variable. For getting ID from URL parameters use

{!$CurrentPage.parameters.Id}

You can get ID in Javascript using above syntax :

var Id = '{!$CurrentPage.parameters.Id}';
console.log(Id);
1
  • there is already an ans to above question with same approach. Can you pls tell me how you are ans providing more info?
    – Ratan Paul
    Commented Jan 28, 2016 at 6:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .