You need to sign in to do that
Don't have an account?
srinivas194861.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;
}
}
<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;
}
}
public ApexPages.PageReference viewAccount()
{
Return new ApexPages.PageReference('\'+selectedAccount.ID);
}
All Answers
public ApexPages.PageReference viewAccount()
{
Return new ApexPages.PageReference('\'+selectedAccount.ID);
}
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);
}