3

I am building a VF page. I'd like to have 2 lookups on the page. One for a built in Account object and the other one for a custom object Market__c.

Short of building a new object that has references to both those objects (Account and Market__c), how can I build a page that has those 2 lookups?

2
  • 1
    If you explain what the use-case is, we could probably help better. Why would you want lookups to things that you don't want to reference on a database table? Commented Jul 15, 2014 at 0:03
  • @DavidSchach I just want to do some calculations and show the user but not necessarily save to the database table. Commented Jul 15, 2014 at 0:13

1 Answer 1

3

Generally, when one talks about lookups, one already has an existing sObject in mind. Suppose we have an sObject called My_Object__c with two lookups:

  1. A lookup to Account called Account__c
  2. A lookup to the Another_Object__c Another_Object__c

Let's write a simple VF Page that allows a user to populate both lookups. But first, let's write a simple controller:

public class TwoInputController {
    public My_Object__c myObject {get;set;}  // the My_Object__c record we're interested in working with

    public TwoInputController(){ // the Constructor for this Class
        this.myObject = new My_Object__c(); // create a new My_Object__c record to play with
        // note myObject hasn't ever been inserted
    }    
}

Now, let's write a simple VF Page that has the two desired lookups:

<apex:page controller="TwoInputController">
    <apex:form>
        <apex:pageBlock title="Check out the Lookups" columns="1">
            <apex:inputField value="{!myObject.Account__c}"/>
            <apex:inputField value="{!myObject.Another_Object__c}"
        </apex:pageBlock>
    </apex:form>
</apex:page>
2
  • 4
    They need not both be "my object" though, and since you can change the field's label with the "label" attribute, you can have them show different text than the actual field. Plenty of ways to reuse existing fields and objects to leverage the lookups.
    – sfdcfox
    Commented Jul 15, 2014 at 3:10
  • Exactly, I've had to do the same thing for clients in the past. As sfdcfox stated you can use another existing sobject to meet these criteria such as Contact for an account lookup. Only thing you would really need to watch out for is filters that may be added to the fields meta data which will filter out some of your results.
    – Double A
    Commented Jul 15, 2014 at 13:23

You must log in to answer this question.

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