2

For an Inline Vf Page how can I get the id of the current object. I want to have the current object id . how can i retieve it use for an inline vf page.

I am embedding it in an Object A while the VF page points to the junction Object of A and B i.e., C. On the Controller, I need the object id Of A so that I may be able to save record of relating A and B.

2 Answers 2

4

If you have a controller, you could use ApexPages.currentPage().getParameters().get('Id').

If you have only Visualforce, you can use {!$CurrentPage.parameters.Id}

Or you can use JavaScript to read the parameters form the window.location.search property. Therefore the following function was helpful for me:

function getUriParams(paramName) {
    var params = decodeURIComponent(window.location.search.slice(1))
          .split('&')
          .reduce(function _reduce (/*Object*/ a, /*String*/ b) {
                b = b.split('=');
                a[b[0]] = b[1];
                return a;
          }, {})
    ;
    if(paramName) return params[paramName]; else return params;
}
2

If you're using the Standard Controller, you can get the ID directly from the record:

<apex:page standardController="Account">
    The current Account Id is: {!Account.Id}. That is all.
</apex:page>
2
  • I am embedding it in an Object A while the VF page points to the junction Object A and B i.e., C. On the Controller, I need the object id Of A so that I may be able to save record of relating A and B. Commented Jul 23, 2014 at 17:55
  • @user2703132 That said, the other answer may be more appropriate in this scenario. Sometimes, knowing the correct tool or programming method to use is half the fun of programming in Visualforce.
    – sfdcfox
    Commented Jul 24, 2014 at 7:11

You must log in to answer this question.

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