Improving the user experience using visualforce | Techila
1083
single,single-post,postid-1083,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

Improving the user experience using visualforce

improve-visualforce

Improving the user experience using visualforce

During a recent conversation on twitter this question popped up again. Is it possible to auto-populate the values on a visualforce page on choosing a lookup? Let’s say you are designing a custom contact manager page. The page contains 4 fields from Account on the page including a lookup. When the user chooses an account value from lookup he would like to see the other 3 fields automatically populated,

 

Sample visualforce code-

 

<apex:page standardController=”Contact” extensions=”AutopopulateController”>

 <apex:form>

   <apex:pagemessages id=”msgs”/>

   <apex:pageblock title=”Contact Create/Edit”>

      <apex:pageblocksection title=”Contact Information”>

       <apex:inputfield value=”{!contact.FirstName}”>

       <apex:inputfield value=”{!contact.LastName}”>

      </apex:inputfield></apex:inputfield></apex:pageblocksection>

       <apex:actionregion>

          <apex:pageblocksection id=”accinfo” title=”Account Information”>

         <apex:inputfield value=”{!contact.AccountId}”>

<!–This method is the key to populate account values–>

            <apex:actionsupport action=”{!populateAccount}” event=”onchange” rerender=”accinfo, msgs”>

         </apex:actionsupport></apex:inputfield>

         <apex:inputfield value=”{!contact.Account.AccountNumber}”/>

         <apex:inputfield value=”{!contact.Account.Amount}”/>

        </apex:pageblocksection>

      </apex:actionregion>

      <apex:pageblockbuttons>

        <apex:commandbutton action=”{!cancel}” value=”Cancel”/>

        <apex:commandbutton action=”{!save}” value=”Save”/>

      </apex:pageblockbuttons>

   </apex:pageblock>

</apex:form>

</apex:page>


The auto-populate controller is as follows-

public with sharing class AutopopulateController

{

 public Contact ContactRecord;

 

 public AutopopulateController(ApexPages.StandardController controller)

 {

  Contact ContactRecord=(Contact) controller.getRecord();

 }

 

 public void populateAccount()

 {

  ContactRecord.Account=[select AccountNumber, Site from Account where id=:ContactRecord.AccountId];

 }

}


You can use any object that is related to populate the code. 

 

 

Courtesyhttp://www.sforce.ninja/2014/06/improving-user-experience-using.html

Author: techila

No Comments

Post A Comment