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
sriphani ramakasriphani ramaka 

write a Vf page to accept account type as input and display all accounts with that account type as a table.when i click on name of account in table it needs to redirect to detail page.could any one help me out

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sriphani,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="AccTypeC">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:inputField value="{!acc.Type}" >
                    <apex:actionSupport event="onchange" action="{!showAcc}" reRender="pbt"/>
                </apex:inputField>
            </apex:pageBlockSection>
            <apex:pageBlockTable value="{!accounts}" var="a" id="pbt">
                <apex:column headerValue="Account Name" > 
                    <apex:commandLink value="{!a.Name}" action="{!showDetail}">
                        <apex:param value="{!a.Id}" name="idForConts" assignTo="{!recid}"/>
                    </apex:commandLink>
                </apex:column> 
                <apex:column value="{!a.Type}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class AccTypeC {
    
    public Account acc {get;set;}
    public List<Account> accounts {get;set;}
    public string recid{get;set;}   
    
    public AccTypeC() {
        acc = new Account();
        accounts = new List<Account>();
    }
    
    public void showAcc() {
        if(acc.Type == 'Prospect'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Prospect'];
        }
        if(acc.Type == 'Customer - Direct'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Customer - Direct'];
        }
        if(acc.Type == 'Customer - Channel'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Customer - Channel'];
        }
        if(acc.Type == 'Channel Partner / Reseller'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Channel Partner / Reseller'];
        }
        if(acc.Type == 'Installation Partner'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Installation Partner'];
        }
        if(acc.Type == 'Technology Partner'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Technology Partner'];
        }
        if(acc.Type == 'Other'){
            accounts = [SELECT Id, Name, Type FROM Account WHERE Type='Other'];
        }
    }
    
    public pageReference showDetail() {
        PageReference pr = new PageReference('/' + recid);
        return pr;
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
sriphani ramakasriphani ramaka
Thanks its working perfectly
 
sriphani ramakasriphani ramaka
Thanks its working perfectly
Ajay K DubediAjay K Dubedi
Hi Sriphani,
Please Try this code:
//VF PAGE

<apex:page controller="SearchAccountController" >
    <apex:form>
    <apex:pageBlock>
        Enter Type&nbsp;
         <apex:selectList size="1" value="{!selectedtype}"> 
         <apex:actionSupport event="onchange"  action="{!showList}" />
        <apex:selectOptions value="{!Items}"/>  
        </apex:selectList>      
        <apex:pageBlockTable value="{!accList}" var ="a">
           <apex:column headerValue="Account Name">
                  <apex:outputLink value="/{!a.Id}"  >{!a.Name} </apex:outputLink>
                </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>     
</apex:page>

//CONTROLLER

public class SearchAccountController {

    public String selectedtype{get;set;}
    
    public List<String> pickListValuesList{get;set;}
   public List<Account> accList{get;set;}
    public SearchAccountController(){       
        accList=new List<Account>();
        pickListValuesList= new List<String>();
        Schema.DescribeFieldResult fieldResult = Account.Type.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(pickListVal.getLabel());
        }  
        
    }
     public List<SelectOption> getItems(){
        try{
        List<SelectOption> options = new List<SelectOption>();
        for(String s:pickListValuesList){
            options.add(new SelectOption(s,s));
        }
      return options;
        }
        catch(Exception e){
            system.debug('Exception at Line Number'+e.getLineNumber()+'because of '+e.getMessage());
            return null;
        }
    }
    public  void showList(){
 
        accList=[select name from Account where type=:selectedtype limit 1000];
    }

}


Thanks,
Ajay Dubedi