0

I am trying to develop a Visualforce page to search account and select from the org. Like we select an account on the contact.

Need something like this on the page:

enter image description here

Controller:

public with sharing class TestControllerForIssue{

  private final Account acct;

    public TestControllerForIssue(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }

}

Visualforce page:

<apex:page standardController="Account" extensions="TestControllerForIssue">
    <apex:form >
            <apex:inputField id="accountNameForTheProduct" value="{!account.Name}"/>
    </apex:form>
</apex:page>

I am only seeing a text box on the page.

2

The lookup icon will be visible when you bind the inputField with lookup/master detail field or you will have to create it custom.

If you don't want to create a custom lookup, and if you want to display the lookup of Account on any other object's page, then that object should have the lookup/master detail field looking up to Account object. Then, you would be able to bind that field to your visualforce page. Assuming, you are creating visualforce page with standard controller as Contact

In that case, your controller would be

public with sharing class TestControllerForIssue{
    public  Contact con {get;set;}
    public TestControllerForIssue(ApexPages.StandardController stdController) {
        this.con = (Contact)stdController.getRecord();
    }
}

And visualforce page would be

<apex:page standardController="Contact" extensions="TestControllerForIssue">
    <apex:form >
        <apex:pageblock >
            <apex:pageblocksection >
                <apex:inputField id="accountNameForTheProduct" value="{!con.AccountId}"/>
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>  

If you want to display the Account's lookup while using the standard controller of Account, then you will have to use another object's instance which has relation with Account or you can create self lookup to Account and you can use that field for binding.

Controller using Account as standard controller and using Contact's field

public with sharing class TestControllerForIssue{
  public Contact con {get;set;}
  public Account acct {get;set;}
    public TestControllerForIssue(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }
}

And visualforce page

<apex:page standardController="Account" extensions="TestControllerForIssue">
    <apex:form >
        <apex:pageblock >
            <apex:pageblocksection >
                <apex:inputField id="accountNameForTheProduct" value="{!con.AccountId}"/>
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>
| improve this answer | |

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.