function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EPSWDEVEPSWDEV 

Visualforce pages with iframes - please help !

I have a visual force page (call it VS1) with a custom controller(CS1). In VS1 I have a IFrame that opens a VS page (VSsub1). VSsub1 displays inputfields tied to a custom object.

Now My VS1 page has 1 button on it called save and upon clicking it I want to save my data (using the CS1). Problem is how do reference the custom object in the iframe in my CS1. Is it even possible.

If you are wondering why i am doing this - so keep a long story short I this VS1 page is used to generate page that on runtime changes the objects it displays. its part of a wizard and its the object type is selected on the previous page. and Yes I know record type does something similar however in our case we cant use it.

Thanks.
Sam.arjSam.arj
This is not possible I believe. We do not have a session object like ASP.NET in Visualforce where you could share information among multiple pages.

Why not have the save button within the iframe itself?

JeremyKraybillJeremyKraybill
Actually, I can envision a couple setups that I think would allow what is being attempted.

potentially easy, but maybe not allowed due to scripting permissions / browser security:
- the save button on the outer page should be able to call, via JS, methods on the inner page to cause a form.submit() to happen. You may need to do an inner page submit then an outer page submit if you want the whole page to redirect in that case.

harder:
- create either an entire new custom object type, which is a direct replica of the custom object being edited in VSsub1, or create a new "scratch" record type. This is needed because you will be causing VSsub1 to save its record frequently to this scratch table before the user clicks "save".
- share some sort of ID or external ID between VS1 and VSsub1. I would suggest using DateTime.now().getTime() to generate a timestamp in the constructor of VS1. Then pass it to VSsub1 via the IFrame URL.
- create a corresponding field in your scratch record that this value will be saved into.
- in your controller for VSsub1, read in this ID and store it as a controller variable.
- use this ID as a hidden field in the VSsub form.
- in your page code for VSsub1, add actionSupport tags to every field which cause a save method to be called on every onChange action. As the user enters data in the form, you will be submitting the data back via ajax and saving to the scratch record.
- when the user clicks save on the outer page, the scratch record is loaded by the external ID, and then you save the "real" record (either by changing record type or by creating a new record).

HTH

Jeremy Kraybill
Austin, TX
EPSWDEVEPSWDEV
Thanks for your ideas and help guys. I figured out a different way to handle the problem I was facing. its a bit of a 'Framework' like approach however it works for what I am trying to do.

Thanks