+ Start a Discussion
srinivas194861.3881088511650579E12srinivas194861.3881088511650579E12 

hi folks, i want to get the selected account detail page when i click the show button in my vf page,plz help me out

my vfpage:
<apex:page controller="picklistclass">
    <apex:form >
        <apex:pageblock >
            <apex:commandButton value="Show" action="{!show}"/>
            <apex:pageblocksection >
                <apex:selectList value="{!selectedAccId}" multiselect="false" size="1">
                    <apex:selectOptions value="{!Accountnames}"></apex:selectOptions>
                </apex:selectList>
<apex:outputField value="{!acc.Name}"/>
<apex:outputField value="{!acc.AccountNumber}"/>
</apex:pageBlockSection>       
</apex:pageblock>
    </apex:form>
</apex:page>

controller:
public with sharing class picklistclass
{
Account account;
    public Account acc { get; set; }
public list<contact> con{get;set;}
    public PageReference show()
    {
list<Account> acc = [Select Name, AccountNumber From Account Where Id =: selectedAccId ];
    return null;      
    }  
   
     public String selectedAccId{ get; set; }
    public List<selectOption> options=new List<selectOption>();
    List<Account> lstnames=new List<Account>();
   
    public List<selectOption> getAccountnames()
    {
        for(Account obj:[select Id,name from Account])
        {
            options.add(new selectOption(obj.name,obj.name));
        }
        return options;
    }
   
}
Best Answer chosen by srinivas194861.3881088511650579E12
Cory CowgillCory Cowgill
If you have a APEX method you can use the ID of the account to route users to the page.

public ApexPages.PageReference viewAccount()
{
    Return new ApexPages.PageReference('\'+selectedAccount.ID);
}

All Answers

Cory CowgillCory Cowgill
If you have a APEX method you can use the ID of the account to route users to the page.

public ApexPages.PageReference viewAccount()
{
    Return new ApexPages.PageReference('\'+selectedAccount.ID);
}
This was selected as the best answer
srinivas194861.3881088511650579E12srinivas194861.3881088511650579E12
thanks cory cowgill
KodiKodi
Hi,
you have to try this type of way,

<apex:page controller="picklistclass">
<apex:form>
<apex:detail/>
......
</apex:form>
</apex:page>

public List<selectOption> getAccountnames()
    {
        for(Account obj:[select Id,name from Account])
        {
            options.add(new selectOption(obj.id,obj.name));
        }
        return options;
    }
public pageReference show()
{
PageReference nextpage=new PageReference('/apex/pagename?Id='+selectedAccountId);
return nextpage.setRedirect(true);
}