+ Start a Discussion
champ_vimalchamp_vimal 

Lookup field in VisualForce page

Hi,

 

I have a visualforce page which has a UserRole field which needs to be lookup.
However, I am using custom controller for same. Can you please let me know how can I display lookup field for same in my visualforce page?

 

 

Thanks,

 

Vimal 

Best Answer chosen by Admin (Salesforce Developers) 
champ_vimalchamp_vimal

Edwin is right. UserRole object does not automatically allow look-up to be shown. And in my case, I am using Custom Controller anyhow.

 

I went through some community posts similar to mine and found some solutions.

 

But I too found a simple, less time consuming solution which worked for me!

 

I added this part in my controller and page code and it worked for me!

 

public TerritoryUsersController()
    {
        stdTerritoryId = ApexPages.currentPage().getParameters().get('stdTerritoryId');
        System.debug('Territory Id-------------->'+stdTerritoryId);
        usr = new User();
        usr.UserRoleId = null;

        
        init();
    } 

 

In page,

 

<apex:outputLabel value="Role" /> <apex:inputfield value="{!usr.UserRoleId}"/> 

All Answers

bob_buzzardbob_buzzard
If you use the inputField component and your field is a lookup, the page will generate the appropriate markup to support the lookup popup page etc.
Edwin VijayEdwin Vijay
Bob, Is there a lookup field which relates to UserRole?????... I guess we only have a lookup to USER....
champ_vimalchamp_vimal

Edwin is right. UserRole object does not automatically allow look-up to be shown. And in my case, I am using Custom Controller anyhow.

 

I went through some community posts similar to mine and found some solutions.

 

But I too found a simple, less time consuming solution which worked for me!

 

I added this part in my controller and page code and it worked for me!

 

public TerritoryUsersController()
    {
        stdTerritoryId = ApexPages.currentPage().getParameters().get('stdTerritoryId');
        System.debug('Territory Id-------------->'+stdTerritoryId);
        usr = new User();
        usr.UserRoleId = null;

        
        init();
    } 

 

In page,

 

<apex:outputLabel value="Role" /> <apex:inputfield value="{!usr.UserRoleId}"/> 

This was selected as the best answer