So, are you saying this could all work w/out a component after all ? If so, then let me put in the original code. Originally it was just a controller putting the values into a VF page which I put into a page layout. But then I realized it needed to go into another VF page and that's when I started down this whole path towards using a component. Here is the original code :


  public with sharing class MyController {

public account acc{get;set;}
public string names{get;set;}
public Contract_Overview__c contract{get;set;}
string contractid;
public Mycontroller(apexpages.standardcontroller controller)
{acc= new account();
contract=[select account__c,Subsidiaries_On_Contract__c from Contract_Overview__c where id =:contractid];

public list<selectoption> getitems()
{List<selectoption> options= new list<selectoption>();
account a =[select name , (select name from Subsidiaries_and_Brands__r) from account where id =:contract.account__c];
For(SubsidiariesAndBrands__c s : a.Subsidiaries_and_Brands__r)
options.add(new SelectOption(s.name,s.name));
return options;

public void execute(){}

public void save()
update contract;


my original VF :

    <apex:page standardController="Contract_Overview__c" extensions="MyControllerClassBackup" tabStyle="Account">

<!-- ********** BUNCH OF VF CODE ETC ETC **********  -->

the part referring to the controller  :

<apex:PageBlock title="My Page Block">

         Related Subsidiaries:  <apex:selectList value="{!names}" multiselect="true">
         <apex:actionSupport event="onclick" action="{!execute}" reRender="field"/>
            <apex:selectOptions value="{!items}"/>

    Subsidiaries Service:<apex:outputtext value="{!names}" id="field"/>

    <apex:commandButton value="Save Changes" action="{!save}"/>


Should all of that work within a VF page when creating a New document ? I'm having trouble testing it because I'm getting this error when I try to create a new one :

"List has no rows for assignment to SObject "

I'm assuming there needs to be an If statement in there somewhere to account for a null value because I haven't chosen an Account yet in order for the query to properly work...? I haven't figured that out.

Thank you very much for all of your help !

  • I'm looking at your page/controller- so you want to embed this whole thing inside of another page? Mar 7 '13 at 22:13
  • Yes, it needs to go inside another page. The other page is the default View for an object, and this is essentially just for one of the fields on that form.
    – user2428
    Mar 8 '13 at 17:08
  • 1
    So on the "default view" of an object (not within a custom VF page) your not going to be able to associate the parent page with the subpage very easily. You can select a VF page as long as it shares a standard controller with the object in question. So your going to have to override your standard edit view with a custom VF page - if your goal is to select a "Subsidiaries_and_Brands__r" and associate it to that "Account" object you don't need a custom component / VF page, you can do this with the standard page layouts. Mar 9 '13 at 4:01
  • Hi @user2428. I went ahead and formatted your code for you. Please check out this documentation - meta.stackexchange.com/questions/22186/… - to learn how to do it properly. Mar 11 '13 at 15:45
  • Thank you Jesse. Any thoughts on the error...? Thanks again.
    – user2428
    Mar 11 '13 at 17:14

I would suggest using a Visualforce Components.

Something along the lines of:

  <apex:attribute name="Acc" type="Account" description="The account object to use"/>
  You are Viewing Account :{!Acc.name}
  <apex:PageBlock title="Subsidiaries">
  <apex:form >

      Press Ctrl to select multiple: <apex:selectList value="{!names}" multiselect="true">
      <apex:actionSupport event="onclick" action="{!execute}" reRender="field"/>
          <apex:selectOptions value="{!items}"/>

      Subsidiaries Selected:<apex:outputtext value="{!names}" id="field"/>

      <apex:commandButton value="Save Changes" action="{!save}"/>


If this file was named ComponentToAdd, you would reference in Visualforce as:

<c:ComponentToAdd Acc="{!Acc}" />

The only issue I could see is the apex:commandButton might error on the {!save}. I am not sure how that would work.


In lots of cases the easiest way to embed VF pages within each other is to use an iframe.

I use them a lot with pop-ups.

You might also consider using a VF component (which is Visualforce's answer to a partial page on par with lots of other web frameworks)


Components can be used with/without a unique controller class. Since this element is part of a form it's going to be tricky to embed it as part of another form trigger the entire form (not just this smaller form) to submit the whole thing to the parent controller.

See Jesse's answer, but your going to have to play with how you pass parameters between the component and the parent and the component to get the assign value on submit.

Long answer short, yes, you will probably need to modify the code a bit before you can drop it into the page as a component and get it to appear and submit properly.

  • Thank you Jordan for your quick response. I was thinking I would have to somehow use a component. I've never used one before and am trying to figure out the proper way to refer to that small page properly. Will I need to actually change any of the coding above or will I be able to just refer to the whole thing from the component ? If I do need to change the coding above will I also need to change the Apex coding which is being used in the extension ? Thanks again Jordan.
    – user2428
    Mar 7 '13 at 20:03
  • Thank you very much guys. I appreciate this help more than I can say. I'm really lost here. This is all part of another functionality which I have been struggling for about a week here. I'm so close to getting it. Thank you so much guys. I appreciate all of the help. I'm really lost here. I've never used components before and I've been struggling to get this whole thing for at least a week now. I hate to do this, but I think I am gonna make a new post for this because I'm out of space here and I want to post the Apex code which this component will need to work with. Sorry for doing this.
    – user2428
    Mar 7 '13 at 21:24
  • You can edit your original post and include more of your source code and where your having problems (; Mar 7 '13 at 21:38
  • Ok - I'm gonna do that - and delete the new post I just made. Thanks !
    – user2428
    Mar 7 '13 at 21:46
  • Ok - I updated my original post to include the Apex. Thanks so much for the help.
    – user2428
    Mar 7 '13 at 22:09

If can just include the VF page in parent VF page, here is a sample code:

<apex:include PageName="<VF page name you want to include>" />

You need to enter page name in PageName attribute not page label value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.