Find your content:

Search form

You are here

How to fetch record id using Salesforce instance URL address


I have VF page and placed that in home side bar component page and I am capturing the Salesforce instance URL from visual force using custom controller.

public String getReferer()
    BrowserURL = ApexPages.currentPage().getHeaders().get('referer'); 
    return browserURL;

Now I want to fetch recorded id using Salesforce instance URL in VF page.

How can I get record id using that URL. Eg: I am getting Salesforce browser URL like: using this URL How can I get Salesforce record id through controller and display the record id in VF page. Like : Record Id: 0019000000GJMHG Can anyone please help me to overcome this issue?

Attribution to: mylife525

Possible Suggestion/Solution #1

I guess you can use the string methods now to pull the ID.

BrowserURL=BrowserURL.right(15);//Pull from right the 15 digit Id

If your org is not update to winter 13 then you can use String.Split('/') and get the last array element value .

Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #2

I've done this in javascript in the past and it boiled down to two regular expressions:

for the / URL format:


and for the ?id= format:


It's not foolproof - any VF page can use custom parameter names, but it covers all standard UI pages I'm aware of any any visualforce that uses a StandardController.

Attribution to: ca_peterson

Possible Suggestion/Solution #3

Not sure if this is completely foolproof, but seems to be working for me -

BrowserURL = ApexPages.currentPage().getHeaders().get('referer').Split('/')[3].left(15);

Attribution to: nickforce
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content