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
Narayan HNarayan H 

Auto-Populate Company Info based on Account Number

I want to auto-populate Account Name and Address fields from matching Account record on entering Account Number. On entering Account Number it should do a auto look-up and if found any matching record then the Account and Address fields to be populated. Here is my VF page. Appreciate your help

<apex:page standardController="RMA__c" >
    <apex:form >
        
         <apex:pageBlock >
           <apex:outputLink value="/{!RMA__c.Id}" >Go Back to Case: {!RMA__c.Case_Number__c}</apex:outputLink>     
         </apex:pageBlock>
           
         <apex:pageBlock title="Create RMA">
             
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>      
             
            <apex:pageBlockSection title="Caller Details" columns="1" collapsible="false">
                <apex:inputField required="true" value="{!RMA__c.First_Name__c}" label="First Name"/>
                <apex:inputField required="true" value="{!RMA__c.Last_Name__c}" label="Last Name"/>
                <apex:inputField required="true" value="{!RMA__c.Phone__c}" label="Phone #"/>
                <apex:inputField required="true" value="{!RMA__c.Email_Address__c}" label="Email Address"/>
                <apex:inputField value="{!RMA__c.Case__c}" label="Case Number"/>
                <apex:inputField value="{!RMA__c.PO_Number__c}" label="PO Number"/>
                <apex:inputField value="{!RMA__c.Account_Number__c}" label="Account Number"/> 
                
                <apex:inputCheckbox value="{!RMA__c.I_don_t_have_an_Account__c}" label="Don't have account">
                 <apex:actionSupport event="onchange" reRender="companyInfo"/>
                </apex:inputCheckbox>                      
           </apex:pageBlockSection>  
             
        
           <apex:pageBlockSection title="Company Details" columns="1" collapsible="true" id="companyInfo"> 
                <apex:inputField value="{!RMA__c.Company_Name__c}" label="Company Name"/>
                <apex:inputField value="{!RMA__c.Street_Address__c}" label="Street Address"/>
                <apex:inputField value="{!RMA__c.City__c}" label="City"/>
                <apex:inputField value="{!RMA__c.State__c}" label="State"/>
               <apex:inputField value="{!RMA__c.Zip_Postal_Code__c}" label="Zip/Postal Code"/>                
          </apex:pageBlockSection>     
                                      
            <apex:detail relatedList="false"/>
        </apex:pageBlock> 
        
    </apex:form>
</apex:page>
v varaprasadv varaprasad
Hi Narayn,

You need to specify action attrobute on action support.based on the you retieve or query data from account.
Please check below sample code.
 
<apex:page standardController="Contact" extensions="ActionSupport">
    <apex:form >
        <apex:pageBlock id="Change">
            <apex:pageBlockSection >
                <apex:inputField value="{!Contact.lastname}"/>
                <apex:inputField value="{!Contact.AccountID}">
                    <apex:actionSupport action="{!Testit}" event="onchange" reRender="Change"/>
                </apex:inputField> 
                <apex:inputField value="{!Contact.Phone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


====================
public class ActionSupport {

    public Contact ConRec;
    public ActionSupport(ApexPages.StandardController controller) {
           ConRec=(Contact)controller.getRecord();
           //ConRec.phone='99999999999';
    }
    public void testit()
    {
        system.debug('Account ID===========>'+ConRec.accountid);        
        Account varacc=[select id,name,phone from Account where id=:ConRec.accountid];
        ConRec.phone=varacc.phone;
    }

}


Hope this helps.


Thanks 
Varaprasad

 
v varaprasadv varaprasad
Based on account field in contact we are displaying account phone number in contact.