You need to sign in to do that
Don't have an account?
MJ09
Pass a parameter to a VF page that's embedded in a standard page layout
I have a VF page that I'm embedding in a standard page layout. I'd like to pass a parameter into the VF page. The VF page's controller will look at the parameter and the current record, then decide what to display on the embedded page.
I have the VF page and controller written. But how can I get the standard page layout editor to pass a parameter in to the VF page? Is that even possible? If not, do you have any other suggestions?
Thanks!
I don't think there is any way to do exactly what you are asking for.
If your only need a few distinct values for this parameter you might consider turning your current page into a custom component with an attribute, then creating a page for each case you need, where each page passes a different parameter value for the attribute.
Alternatively, could you do something with a custom field on the record your page displays?
If I understand correctly, you're trying to pass some value from the object on whose detail page you will embed your VF page to the controller. If so:
For embedding a VF page in a standard page, you create the page with the standard controller of that object and get access to all the fields of that object in the extension that you may be writing for custom behaviour as you can't just write a custom controller. Lookup controller extensions in the documentation for more.
Thank you for the responses. I'm starting to think, though, that I really can't do what I want to.
I have an object that has several custom fields whose values are computed by a potentially long-running batch process. On the standard view page (using a standard page layout), instead of always displaying the value of each field, I'd like to first check whether the batch process is running, and if it is, display "Values are being calculated." If the batch process isn't running, I'll display the field value.
My thought was to create a VF page that displays this for a single field. The page uses the object's standard controller, so the page can be included in the standard page layout. The page also has a controller extension, which checks whether the batch process is running. (I know how to do that.) Rather than develop a separate copy of this page for each field, I'd like to have my page accept a querystring parameter that gives either the name of the field or just the field's current value. The controller extension should determine whether the batch process is running, and then populate a binding variable (which the VF page then displays) with either the current value of the field or the string "Values are being calculated."
Once I have this page implemented, I'll include it on the standard page layout for each of my calculated fields, using different query string values for each field.
The trick here is for the VF page, which is embedded in a standard page layout, to accept a querystring that indicates which field it's being called for. While I can place the VF page on the standard page layout, I can't find a way to get the standard page layout editor pass a querystring parameter into the page. A second problem is that I apparently can't put the same VF page on the same standard page layout more than once. So it appears that there's no way to make my embedded VF page re-usable. I'll have to come up with a separate VF page for each field or find some other approach.
Why don't you create an apex component for the same and then use that repeatedly in your VF page that gets displayed on the detail page? You can pass the field names as attributes to the component and then call the component in your VF page repeatedly passing different field names.
Thanks, Manu. That would work, but it would have implications on the display. All the fields would have to be displayed together -- I couldn't scatter them throughout the page layout. If the user wants to display them in a different order, I'd have to edit my VF page -- the user couldn't use the page layout editor to re-arrange them.
I just created an Idea for this. If you agree this would be useful, please vote at https://sites.secure.force.com/ideaexchange/ideaList?c=09a30000000D9xt&sort=recent
Sorry, no luck. The only parameter that the standard page layout passes into an embedded VF page is the ID of the record.
Hi,
One way of doing this could be we get the id of the record for which the standard page is displayed. Then using that id, query the data you want to display and show it.
Like suppose you embedded a VF page in case detail page, then to get the id of the current record in your embedded VF page you can use:
String caseId=ApexPages.currentPage().getParameters().get('id');
Using this id, query the case object or any other related object and show data accordingly.
Hope it helps.
Imagine a scenario where a VF page accepts a parameter "type" and displays two different things depending on whether the value is "a" or "b." Imagine I want to put the VF page on the record page twice, once with parameter "a" and a second time with "b." I was asking if there's any way to do that. (Yes, I know I could split it into 2 separate VF pages, but that's not what I was asking.)
Obviously, with the advent of Lightning Components (which weren't available when I posted my question in 2010), this is now possible using either Aura or LWC. After 10+ years, the answer to my question isn't relevant anymore, except out of curiosity as to whether it was possible.