+ Start a Discussion
rebvijkumrebvijkum 

how can i get id from url in visualforcepage

my vfp code:
<apex:page controller="GetURLCOREnew">
  <apex:outputText  value="{!myurll}"/>
</apex:page>

controller:
public class GetURLCOREnew {

    public string sfURL= System.URL.getSalesforceBaseUrl().getHost();
    public string myURL= 'https://'+sfUrl+'/apex/CoreBenefit_PDF?id='+;
   
    public String getsfurll() {
        return sfURL;     
    }
    public String getmyurll() {
        return myURL;     
    }
}

the outpul should be:          https://vsp--kmbuild--c.cs10.visual.force.com/apex/CoreBenefit_PDF?id=kA3J0000000CbHQ

i should get the id from the visualforce page

Thanks in advance
Best Answer chosen by rebvijkum
U JayU Jay
This code will help you to print "https://vsp--kmbuild--c.cs10.visual.force.com/apex/CoreBenefit_PDF?id=kA3J0000000CbHQ"​ when ever the page hold "kA3J0000000CbHQ" as value for the parameter ID.
my vfp code:
<apex:page controller="GetURLCOREnew">
  <apex:outputText  value="{!myurll}"/>
</apex:page>

controller:
public class GetURLCOREnew {

    public string sfURL= System.URL.getSalesforceBaseUrl().getHost();
    public string myURL{get;set;}
    public GetURLCOREnew(){
     String currentParam = ApexPages.currentPage().getparameters().get('ID'); 
     myURL= 'https://'+sfUrl+'/apex/CoreBenefit_PDF?id='+ currentParam;   
    }
}

Is it , what you needed?

All Answers

rebvijkumrebvijkum
i need to copy the id from visualforce page into controller.
i used {!$CurrentPage.parameters.id}, but didn't got the id.
BroncoBoyBroncoBoy
One theing you could try is using the apex: param tag, give it the value of the id and then use the assignTo attribute to put it in the controller:

Example:

Visualforce Code
<apex:param value="{!$CurrentPage.parameters.id}" assignTo="{!IdChosen}" name="contIdParam" />

Apex Code:

public String IdChosen
    {
        get;
        set;
    }

Explanation:
So the <apex:param> component will store the Id parameter using the value attribute then using the assignTo attribute, it will assign that value to the idChosen property.

Potentiall Helpful References:
http://blog.jeffdouglas.com/2010/03/03/passing-parameters-with-a-commandlink/

https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_param.htm
Ravikant kediaRavikant kedia
Use below line of code to get id in visualforce page:

{!JSENCODE($CurrentPage.parameters.id)}
U JayU Jay
This code will help you to print "https://vsp--kmbuild--c.cs10.visual.force.com/apex/CoreBenefit_PDF?id=kA3J0000000CbHQ"​ when ever the page hold "kA3J0000000CbHQ" as value for the parameter ID.
my vfp code:
<apex:page controller="GetURLCOREnew">
  <apex:outputText  value="{!myurll}"/>
</apex:page>

controller:
public class GetURLCOREnew {

    public string sfURL= System.URL.getSalesforceBaseUrl().getHost();
    public string myURL{get;set;}
    public GetURLCOREnew(){
     String currentParam = ApexPages.currentPage().getparameters().get('ID'); 
     myURL= 'https://'+sfUrl+'/apex/CoreBenefit_PDF?id='+ currentParam;   
    }
}

Is it , what you needed?
This was selected as the best answer