function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nagalakshminagalakshmi 

How to create the look up field on visual force page and how assign the users in to that look up

Hi,

 

My requirement is, want to create the look up with out using the backend field and assign the users in to that look up. which data type i need to use for look up. And how to create the look up on visual force page. how to assign the users to look up. Please any one help me how to solve these. Thank you in advance.

 

Thanks,

Lakshmi.

Shashikant SharmaShashikant Sharma

Use this

 

Add this Script

 

<script>
    
      function showLookup(ctrlID,objKeyPrefix)
        { 
            openLookup("/_ui/common/data/LookupPage?lkfm=editPage&lknm="+ ctrlID +"&lktp="+objKeyPrefix,500);           
         }
</script>

 

 

 

 

<apex:pageBlockSectionItem id="pbsiID">
                    Field Label
                    <apex:OutPutPanel id="opAccountID">
                        <apex:inputText id="vField_AccountName" value="{!AccountNameForSearch}" style="width:150px"/>
                        <apex:inputHidden id="vField_AccountName_lkid" value="{!lookupAccountID}"/>
                        <apex:inputHidden id="vField_AccountName_lkold" value="{!lookupAccountNameForOld}"/>
                        
                        <apex:image url="/s.gif" alt="Lookup (New Window)" styleClass="lookupIcon" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onclick="javascript&colon;showLookup('pageID:formID:pageBlockID:pbsID:pbsiID:vField_AccountName','001')" title="Lookup (New Window)"/>
                    </apex:OutPutPanel>
                </apex:pageBlockSectionItem>

pageID:formID:pageBlockID:pbsID:pbsiID:vField_AccountName : Change this id to your vField controls id

 

'001' is Account objects Key Prefix , give your key prefix

 

Please ask if any confusion.

 

 

nagalakshminagalakshmi

Hi, 

 

How can i get the id's of pageID:formID:pageBlockID:pbsID:pbsiID:vField_AccountName : Change this id to your vField controls id. Please help How i keep these id's in to my page.

 

 

Thanks,

Lakshmi.

Shashikant SharmaShashikant Sharma

Just see the id in view source and repalce it.

 

Could you please share your code I will have more idea about your issue how to use this solution.

goubkgoubk

since lookup works on the real reference fields like ownerid(lookup to User), accountid (lookup to account) on contact object. 

if you are using standard controller then we can easly do this by binding the object name. lookup filed name into the input filed tag.


if you want to build dummy lookup field using custom controller please follow the below workaround.

 

vf pgae :

 

<apex:page controller="objectList">
   <apex:form >
  <apex:pageBlock mode="detail">
<!-- this is dummy lookup field on vf page-->
   <apex:inputField value="{!acc.ownerid}" />

<!-- passing lookup field value i.e userdid into controller methos  on button click-->
   <apex:commandButton action="{!searchdata}" title="search" value="search"/>


   </apex:pageblock>       
  </apex:form>                       
</apex:page>

 

controller :

public class objectList{

 

// creating dummy apex property
public Account acc {get;set;}

 

 // creating dummy method

   public String getAccount() {
        return null;
    }

public pagereference searchdata()
{

 

//you can fetch dummy lookup field vale here and process accordingly.
 System.debug('@@@@@@@@@@@'+acc.ownerid);
 return null;
}
 
  public objectList()
  {

 // instantiate your dummy object

    acc = new Account();
  }
 

i know i am replying very late but today i got this idea and tested it worked for me. please let me know if it works or not.