Visualforce page to display Account Information based on User input.

Requirement: User enters Account Name and clicks command button to get Account details.

Solution: This can be achieved by writing Visualforce page.

Visualforce page:

Entering the Account name : Blackbeards Grog Emporium 

Clicking on Display Data command button will display Account Name and Industry.


Visualforce page:
<apex:page controller="DisplayAccountDtlController" >
    <apex:form >
       <apex:pageBlock title="Accounts">
           <apex:pageBlockButtons >
              <apex:commandButton value="Display Data" action="{!getdata}" />
           </apex:pageBlockButtons>
           <apex:pageBlockSection >          
           <apex:outputLabel value="Enter Account Name" />
           <apex:inputText value="{!accname}"/>
           </apex:pageBlockSection>
           <apex:pageBlockTable value="{!acc}" var="a">
              <apex:column value="{!a.name}"/>
              <apex:column value="{!a.industry}"/>
           </apex:pageBlockTable>
       </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class DisplayAccountDtlController {

    public list<account> acc {set;get;}  
    public string accname {set;get;}
   
    public void getdata(){
       acc = [select name, industry from account where name = :accname];      
    }
}


Cheers !

Post a Comment

0 Comments