Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

I'm trying to develop a visualforce custom component which is an entity chooser. This custom component displays a UI which helps to browse some records. It's possible to select one record, and I'd like to get it from outside the component or its controller.

I've looked at the standard salesforce binding with an assignTo bug it's not bidirectional...

Hope someone can help me. Thanks

1 Answer

0 votes
by (32.1k points)
edited by

Hey! Are you trying to pass an object into the component? If yes, then you know that objects are passed by reference. So, if your component has an attribute which takes an object, and some functions are applied to it, your other page controller will access the changed values.

If you want to pass in a shell object, that is, in case your UI is allowing a user to select an Account, use the following code:

Class SelectedAccount


  public Account theAccount {get;set;}



<apex:component controller="ComponentController">

   <apex:attribute type="SelectedAccount" name="userSelectedAccount" description="Selected Account" assignTo="{!selectedAccount}"


Component Controller:

public class ComponentController


  public selectedAccount;

  public void ComponentController(){}

  public PageReference selectAccountFromUI(Account selected)


    selectedAccount.theAccount = selected;

    return null;



Page using the Component:

<c:MyAccountComponent userSelectedAccount="{!instanceOfSelectedAccount}"/>

Are you willing to pursue a career in Salesforce, here's an opportunity for you Salesforce certification provided by intellipaat! 

Browse Categories