+ Start a Discussion
SF DakshendraSF Dakshendra 

firstly we need to hide the fields first name and last name, when we choose lookup in gift card holder automatically it displays first name and last name and gift card holder name same as in first name and last name

User-added image
Mahesh DMahesh D
Hi 

Please paste your existing code, so that it will be easy to help you.

For these kind of requirements, we have to use the <apex:actionSupport tab with reRender attribute.

Please look into the below link:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionSupport.htm

Please do let me know if it helps you.

Regards,
Mahesh
SF DakshendraSF Dakshendra
Here is the cdoe, 
<apex:pageBlock >              
            <table width="25%" align="center">
                        <tr>
                            <td style="font-size:10pt;" align="right">Gift Card Holder:&nbsp;</td>
                            
                            <td><apex:inputField value="{!giftpurchase.Gift_Card_Holder__c}" required="true"/></td>
                        </tr>
                   
                       <tr>
                            <td style="font-size:10pt;" align="right">First Name:&nbsp;</td>
                            
                            <td><apex:inputField value="{!giftcardholder.First_Name__c}" required="true"/></td>
                        </tr>
                        <tr>
                            <td style="font-size:10pt;" align="right" >last Name:&nbsp;</td>
                            <td><apex:inputField value="{!giftcardholder.Last_Name__c}" required="true"/></td>
                        </tr>
                        
                        <tr>
                            <td style="font-size:10pt;" align="right">Purchasing Amount:&nbsp;</td>
                            <td><apex:inputField value="{!giftpurchase.Cost__c }" required="true" /></td>
                        </tr>
                        <tr>
                            <td style="font-size:10pt;" align="right">Gift Card Square Number:&nbsp;</td>
                            <td><apex:inputField value="{!giftpurchase.Gift_Card_Square_number__c }" required="true" /></td>
                        </tr>
                        <tr>
                            <td style="font-size:10pt;" align="right">Payment Confirmation Code:&nbsp;</td>
                            <td><apex:inputField value="{!giftpurchase.Payment_confirmation_code__c}" required="true" /></td>
                        </tr>
                        
              </table>
              <br/><center><apex:commandButton value="Save" action="{!savegift}" />&nbsp;&nbsp;<apex:commandButton value="Cancel" action="{!paymenbackpage}" Immediate="true"/></center><br/>
              </apex:pageBlock> 

Thanks
Dakshendra.R
Mahesh DMahesh D
Hi

Please find the below code:

Visualforce Page:
<apex:pageBlock >              
	<table width="25%" align="center">
		<tr>
			<td style="font-size:10pt;" align="right">Gift Card Holder:&nbsp;</td>
			
			<td><apex:inputField value="{!giftpurchase.Gift_Card_Holder__c}" required="true">
				<apex:actionSupport event="onchange" action="{!populateName}" reRender="fnId, lnId" />
			</apex:inputField>
			</td>
		</tr>
   
	   <tr>
			<td style="font-size:10pt;" align="right">First Name:&nbsp;</td>
			
			<td><apex:inputField value="{!giftcardholder.First_Name__c}" required="true" id="fnId"/></td>
		</tr>
		<tr>
			<td style="font-size:10pt;" align="right" >last Name:&nbsp;</td>
			<td><apex:inputField value="{!giftcardholder.Last_Name__c}" required="true" id="lnId"/></td>
		</tr>
		
		<tr>
			<td style="font-size:10pt;" align="right">Purchasing Amount:&nbsp;</td>
			<td><apex:inputField value="{!giftpurchase.Cost__c }" required="true" /></td>
		</tr>
		<tr>
			<td style="font-size:10pt;" align="right">Gift Card Square Number:&nbsp;</td>
			<td><apex:inputField value="{!giftpurchase.Gift_Card_Square_number__c }" required="true" /></td>
		</tr>
		<tr>
			<td style="font-size:10pt;" align="right">Payment Confirmation Code:&nbsp;</td>
			<td><apex:inputField value="{!giftpurchase.Payment_confirmation_code__c}" required="true" /></td>
		</tr>
				
	  </table>
	  <br/><center><apex:commandButton value="Save" action="{!savegift}" />&nbsp;&nbsp;<apex:commandButton value="Cancel" action="{!paymenbackpage}" Immediate="true"/></center><br/>
</apex:pageBlock>

Part of controller:
 
public void populateName(){
    Gift_Card_Holder__c gc = [Select Id, First_Name__c, Last_Name__c from Gift_Card_Holder__c where Id =: giftpurchase.Gift_Card_Holder__c];
	giftcardholder.First_Name__c = gc.First_Name__c;
	giftcardholder.Last_Name__c = gc.Last_Name__c;
}

Please do let me know if it helps you.

Regards,
Mahesh

 
SF DakshendraSF Dakshendra
When i choose look up for gift card holder automatically first name and last name are need to be hidden.How can i get that?
Mahesh DMahesh D
Hi

Please find the below VF page:
 
<apex:pageBlock >              
	<table width="25%" align="center">
		<tr>
			<td style="font-size:10pt;" align="right">Gift Card Holder:&nbsp;</td>
			
			<td><apex:inputField value="{!giftpurchase.Gift_Card_Holder__c}" required="true">
				<apex:actionSupport event="onchange" action="{!populateName}" reRender="fnId, lnId" />
			</apex:inputField>
			</td>
		</tr>
   
	   <tr>
			<td style="font-size:10pt;" align="right">First Name:&nbsp;</td>
			
			<td><apex:inputField value="{!giftcardholder.First_Name__c}" required="true" id="fnId" rendered="{!displayName}"/></td>
		</tr>
		<tr>
			<td style="font-size:10pt;" align="right" >last Name:&nbsp;</td>
			<td><apex:inputField value="{!giftcardholder.Last_Name__c}" required="true" id="lnId" rendered="{!displayName}"/></td>
		</tr>
		
		<tr>
			<td style="font-size:10pt;" align="right">Purchasing Amount:&nbsp;</td>
			<td><apex:inputField value="{!giftpurchase.Cost__c }" required="true" /></td>
		</tr>
		<tr>
			<td style="font-size:10pt;" align="right">Gift Card Square Number:&nbsp;</td>
			<td><apex:inputField value="{!giftpurchase.Gift_Card_Square_number__c }" required="true" /></td>
		</tr>
		<tr>
			<td style="font-size:10pt;" align="right">Payment Confirmation Code:&nbsp;</td>
			<td><apex:inputField value="{!giftpurchase.Payment_confirmation_code__c}" required="true" /></td>
		</tr>
				
	  </table>
	  <br/><center><apex:commandButton value="Save" action="{!savegift}" />&nbsp;&nbsp;<apex:commandButton value="Cancel" action="{!paymenbackpage}" Immediate="true"/></center><br/>
</apex:pageBlock>

Part of Controller Code:
 
public Boolean displayName {get; set;}

In the Constructor assign the value to true.
displayName = true;

public void populateName(){
    Gift_Card_Holder__c gc = [Select Id, First_Name__c, Last_Name__c from Gift_Card_Holder__c where Id =: giftpurchase.Gift_Card_Holder__c];
	giftcardholder.First_Name__c = gc.First_Name__c;
	giftcardholder.Last_Name__c = gc.Last_Name__c;
	displayName = false;
}

Please do let me know if it helps you.

Regards,
Mahesh