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
txmapptxmapp 

create a look up parent to child visual force page

i created 2 custom objects ,the parent is Vacante__c, and the child es Aplicante__c, both are related by a lookup field .
on the related list that shows all the childs for the parent i want to create a new button or override the new button, when i click send me to other page, that show me a label with the name of the parent and a lookup field for search a child ,in this case Aplicante__c, i have created a VFP BUT the icon of lookup not appear ,

i want to make a select by name of the aplicante__c, and when i have the child required update this child, only the field Vacante__c on the object aplicaante__c, with the name or id of the actual parent, i dont know how is the lookup search if save the name of parent or id

im new in VF and apex

here is my code can someboby helpme?

 

actually  it run when i work with the field that is a lookup field, when i work with otre field example Name, not show me the lookup icon

only want search by a lookpup, of parent to child, and no like me code thar search of child to parent

 

public with sharing class MyCustomLookupController1 {
   
    public Aspirante__c aspirante {get;set;}

    public MyCustomLookupController1() {
    aspirante= new Aspirante__c();
    
    }
      
}

 my vfp

<apex:page controller="MyCustomLookupController1" id="Page" tabstyle="Contact">

  <script type="text/javascript"> 
  function openLookup(baseURL, width, modified, searchParam){
    var originalbaseURL = baseURL;
    var originalwidth = width;
    var originalmodified = modified;
    var originalsearchParam = searchParam;
    
    var lookupType = baseURL.substr(baseURL.length-3, 3);
    if (modified == '1') baseURL = baseURL + searchParam;
    
    var isCustomLookup = false;
    
    // Following "001" is the lookup type for Account object so change this as per your standard or custom object
    if(lookupType == "001"){
  
      var urlArr = baseURL.split("&");
      var txtId = '';
      if(urlArr.length > 2) {
        urlArr = urlArr[1].split('=');
        txtId = urlArr[1];
      }
      
      // Following is the url of Custom Lookup page. You need to change that accordingly
      baseURL = "/apex/CustomAccountLookup1?txt=" + txtId;
      
      // Following is the id of apex:form control "myForm". You need to change that accordingly
      baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
      if (modified == '1') {
        baseURL = baseURL + "&lksearch=" + searchParam;
      }
      
      // Following is the ID of inputField that is the lookup to be customized as custom lookup
      if(txtId.indexOf('Name') > -1 ){
        isCustomLookup = true;
      }
    }
    
    
    if(isCustomLookup == true){
      openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
    }
    else {
      if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;
      openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
    } 
  }
</script>

<apex:sectionHeader title="Demo"  subtitle="Custom Lookup1" />

    <apex:form id="myForm">  
        <apex:PageBlock id="PageBlock">     
            <apex:pageBlockSection columns="1" title="Custom Lookup">
        <apex:inputField id="Aspirante__c" value="{!aspirante.Vacante__c}"  /> <!--i dont know how to work with other field that isn't lookup-->
            </apex:pageBlockSection>
        </apex:PageBlock>
    </apex:form>
       
</apex:page>

 

 

 

TheSwamiTheSwami

The Lookup icon only appears for lookup fields.  It sounds like you are expecting the icon to be displayed for a name field - is that right?

 

 <apex:inputField id="Aspirante__c" value="{!aspirante.Vacante__c}"  /> <!--i dont know how to work with other field that isn't lookup-->

 

You can put any edittable field as the value for an inputField like this:

 

  <apex:inputField id="Aspirante__c" value="{!aspirante.name}"  />

But it will not show a lookup icon because it is not a lookup field.