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 

how to save values lookup field on vf

i want to update a lookup in my visual force page

 

i can search the parent record,but i can't save o update this values in the lookup field

i don't know how to get the value from de vfp 

 

My parent object Vacante__c

Child  Aspirante__c

 

public with sharing class MyCustomLookupController1 {
    public String nombre {get;set;}
    public String vacante {get; set;}
    String nameVacante;
   
  
    public Aspirante__c aspirante1 {get;set;}
    
     
    public Vacante__c oVacante{get;set;}
    
    public MyCustomLookupController1() {
    aspirante1= new Aspirante__c();
    oVacante=new Vacante__c();
    }
    
    
    public void save() 
                {
                    nameVacante=//VALUE THAT I SELECT FROM LOOKUP FIELD

                     Vacante__c oVacante=[Select Id,Name from Vacante__c where Name=:nameVacante];    
                      
                       
                   	Aspirante__c aspirante1 = [Select Name, Vacante__c from Aspirante__c where Name='Thomas'];
                             vacante =aspirante1.Vacante__c ;
                             nombre= aspirante1.Name;
                  
                   
                  
                           
                            aspirante1.Vacante__c=oVacante.Id;
                    //This will update the custom object
                   update aspirante1;
                 }  
    
}

 

   <apex:form id="myForm">  
        <apex:PageBlock id="PageBlock">     
            <apex:pageBlockSection columns="1" title="Asignar vacante">
        <apex:inputField id="Vacante__c" value="{!aspirante1.Vacante__c}"  />
         <P>Name: 
               <apex:inputText value="{!nombre}"/></P>
        <P>Vacante : 
               <apex:inputText value="{!vacante}"/></P>
          
        <P><apex:commandButton action="{!save}" 
                value="Guardar"/></P>
            </apex:pageBlockSection>
        </apex:PageBlock>
    </apex:form>

 

 

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet:

 

<apex:page controller="lookup2" >
<apex:form id="myForm">
<apex:PageBlock id="PageBlock">
<apex:pageBlockSection columns="1" title="Asignar vacante">
<apex:inputField id="Vacante__c" value="{!aspirante1.Vacante__c}" />
<P>Name:
<apex:inputText value="{!nombre}"/></P>
<P>Vacante :
<apex:inputText value="{!vacante}"/></P>

<P><apex:commandButton action="{!save}"
value="Guardar"/></P>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:form>
</apex:page>

======Apex Controller============

public class lookup2 {
public String nombre {get;set;}
public String vacante {get; set;}
public Aspirante__c aspirante1 {get;set;}


public lookup2()

{
aspirante1= new Aspirante__c();

}


public void save()
{

Aspirante__c aspirante2 = [Select id, Name, Vacante__c from Aspirante__c where Name='Thomas' Limit 1];

aspirante2.Vacante__c=aspirante1.Vacante__c; //This puts the Lookup value that you select from Vf page and put it  in the "aspirante2" object
aspirante2.Name=nombre;

update aspirante2; //This will update the custom object aspirante2
}


}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

txmapptxmapp

hi thanks i just that i want

 

but i have another cuestion

i create a new button onthe Interface of the object Aspirante__c this button send me to the page 

i dont know how to pass the id of the record Aspirante__c

 

Aspirante__c aspirante2 = [Select id, Name, Vacante__c from Aspirante__c where Name='Thomas' Limit 1];

i want to remove 'thomas ' and pass to  the query id of the prior record

 

for the button only create a button and with jscritp redirect tho my page

 

window.location.href = "/apex/MyCustomLookup"

 

can you helpe??