You need to sign in to do that
Don't have an account?
Kumar__Mayank
Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList
Hi All..
I am new to development So I need help. i have one requirement where I have to select record type for Acoount from drop down and based on record type it should return accounts created under same record type in table without refreshing complete page. Morever I should have pagination for those returned account records.
Visualforce Page:
<apex:page controller="RecordTypeAccounts" title="Find the Accounts of corresponding record type" sidebar="False">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="selectedRecordType" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Choose Record Type for Account" for="rt" />
<apex:panelGrid columns="2">
<apex:selectList value="{!RecordType}" multiselect="false" size="1">
<apex:selectOptions value="{!rectypes}"/>
<apex:actionSupport event="onchange" action="{!getAccList}" reRender="Account_list"/>
</apex:selectList>
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!AccList}" var="item" id="Account_list">
<apex:column value="{!item.name}"/>
<apex:column value="{!item.rating}"/>
<apex:column value="{!item.phone}"/>
<apex:column >
<apex:commandLink value="Click here" action="{!detailPage}">
<apex:param name="abc" value="{!item.id}" />
</apex:commandLink>
</apex:column>
<apex:panelGrid columns="8" id="PanelId">
<apex:commandLink action="{!AccPagination.previous}" rerender="Account_list">
<apex:outputLabel value="<<Previous" style="font-weight: bold;"/>
</apex:commandlink>
<apex:commandLink action="{!AccPagination.next}" rerender="Account_list">
<apex:outputLabel value="Next>>" style="font-weight: bold;"/>
</apex:commandlink>
</apex:panelGrid>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class RecordTypeAccounts {
public string showaccid { get; set; }
String recType;
public List<Account> AccList {get;set;}
public List<SelectOption> getrectypes() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('','--Select Record Type --'));
for(RecordType rt:[select id,name from RecordType where sobjecttype='Account']){
options.add(new SelectOption(rt.id,rt.name));
}
return options;
}
public String getRecordType() {
return recType;
}
public void setRecordType(String recType) {
this.recType= recType;
}
public ApexPages.StandardSetController AccPagination
{
get{
if(AccPagination== null)
{
AccPagination= new ApexPages.StandardSetController(Database.getQueryLocator([select name,rating,phone from account where recordtypeid =: recType]));
}
return AccPagination;
}
set;
}
Public List<Account> getAcclist()
{
AccPagination.setPageSize(5);
return (List<Account>) AccPagination.getRecords();
}
public PageReference detailPage() {
showaccid = System.currentPageReference().getParameters().get('abc');
PageReference nextPage = new PageReference('/' + showaccid);
nextPage.setRedirect(true);
return nextPage;
}
}
I am new to development So I need help. i have one requirement where I have to select record type for Acoount from drop down and based on record type it should return accounts created under same record type in table without refreshing complete page. Morever I should have pagination for those returned account records.
Visualforce Page:
<apex:page controller="RecordTypeAccounts" title="Find the Accounts of corresponding record type" sidebar="False">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="selectedRecordType" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Choose Record Type for Account" for="rt" />
<apex:panelGrid columns="2">
<apex:selectList value="{!RecordType}" multiselect="false" size="1">
<apex:selectOptions value="{!rectypes}"/>
<apex:actionSupport event="onchange" action="{!getAccList}" reRender="Account_list"/>
</apex:selectList>
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!AccList}" var="item" id="Account_list">
<apex:column value="{!item.name}"/>
<apex:column value="{!item.rating}"/>
<apex:column value="{!item.phone}"/>
<apex:column >
<apex:commandLink value="Click here" action="{!detailPage}">
<apex:param name="abc" value="{!item.id}" />
</apex:commandLink>
</apex:column>
<apex:panelGrid columns="8" id="PanelId">
<apex:commandLink action="{!AccPagination.previous}" rerender="Account_list">
<apex:outputLabel value="<<Previous" style="font-weight: bold;"/>
</apex:commandlink>
<apex:commandLink action="{!AccPagination.next}" rerender="Account_list">
<apex:outputLabel value="Next>>" style="font-weight: bold;"/>
</apex:commandlink>
</apex:panelGrid>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class RecordTypeAccounts {
public string showaccid { get; set; }
String recType;
public List<Account> AccList {get;set;}
public List<SelectOption> getrectypes() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('','--Select Record Type --'));
for(RecordType rt:[select id,name from RecordType where sobjecttype='Account']){
options.add(new SelectOption(rt.id,rt.name));
}
return options;
}
public String getRecordType() {
return recType;
}
public void setRecordType(String recType) {
this.recType= recType;
}
public ApexPages.StandardSetController AccPagination
{
get{
if(AccPagination== null)
{
AccPagination= new ApexPages.StandardSetController(Database.getQueryLocator([select name,rating,phone from account where recordtypeid =: recType]));
}
return AccPagination;
}
set;
}
Public List<Account> getAcclist()
{
AccPagination.setPageSize(5);
return (List<Account>) AccPagination.getRecords();
}
public PageReference detailPage() {
showaccid = System.currentPageReference().getParameters().get('abc');
PageReference nextPage = new PageReference('/' + showaccid);
nextPage.setRedirect(true);
return nextPage;
}
}
In your code 'pageBlockTable' is directly bind to AccList and AccList is only updated when record type is changed.
Need to add a new method 'getAccounts' in controller and bind it to 'pageBlockTable' in vfp.
Make the following changes in code-
1. Update Controller -
public class RecordTypeAccounts {
public string showaccid { get; set; }
String recType = 'typeId';
public List<Account> AccList {get;set;}
public List<SelectOption> getrectypes() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('typeId','--Select Record Type --'));
for(RecordType rt:[select id,name from RecordType where sobjecttype='Account']){
options.add(new SelectOption(rt.id,rt.name));
}
return options;
}
public String getRecordType() {
return recType;
}
public void setRecordType(String recType) {
this.recType= recType;
}
public ApexPages.StandardSetController AccPagination
{
get{
if(AccPagination== null)
{
AccPagination= new ApexPages.StandardSetController(Database.getQueryLocator([select name,rating,phone from account where recordtypeid =: recType]));
}
return AccPagination;
}
set;
}
Public void getAcclist()
{
AccPagination = null;
AccPagination.setPageSize(5);
// Acclist = AccPagination.getRecords();
}
public List<Account> getAccounts(){
AccPagination.setPageSize(5);
return (List<Account>) AccPagination.getRecords();
}
public PageReference detailPage() {
showaccid = System.currentPageReference().getParameters().get('abc');
PageReference nextPage = new PageReference('/' + showaccid);
nextPage.setRedirect(true);
return nextPage;
}
}
2. Update VFP -
<apex:page controller="RecordTypeAccounts" title="Find the Accounts of corresponding record type" sidebar="False">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="selectedRecordType" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Choose Record Type for Account" for="rt" />
<apex:panelGrid columns="2">
<apex:selectList value="{!RecordType}" multiselect="false" size="1">
<apex:selectOptions value="{!rectypes}"/>
<apex:actionSupport event="onchange" action="{!getAccList}" reRender="Account_list"/>
</apex:selectList>
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!Accounts}" var="item" id="Account_list">
<apex:column value="{!item.name}"/>
<apex:column value="{!item.rating}"/>
<apex:column value="{!item.phone}"/>
<apex:column >
<apex:commandLink value="Click here" action="{!detailPage}">
<apex:param name="abc" value="{!item.id}" />
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
<apex:panelGrid columns="8" id="PanelId">
<apex:commandLink action="{!AccPagination.previous}" rerender="Account_list">
<apex:outputLabel value="<<Previous" style="font-weight: bold;"/>
</apex:commandlink>
<apex:commandLink action="{!AccPagination.next}" rerender="Account_list">
<apex:outputLabel value="Next>>" style="font-weight: bold;"/>
</apex:commandlink>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
</apex:page>
Let me know if any help is required.
If it help you then don't forget to mark it as 'HelpFull'
All Answers
If you are using a function in action attribute, then its return type must be void or pagereference.
In,
action="{!getAccList}"
You are using a function getAccList() with return type list.
Hence the error.
You can modify your function like this:
Public void getAcclist()
{
AccPagination.setPageSize(5);
Acclist=(List<Account>) AccPagination.getRecords();
}
Public void getAcclist()
{
// For reset StandardSetController object
AccPagination = null;
AccPagination.setPageSize(5);
Acclist = AccPagination.getRecords();
}
2. For pagination -
Use this code as a reference - http://fdcpoint.com/salesforce/pagination-using-standard-set-controller-salesforce/
below actions are not working as we are not returning AccPagination list.
action="{!AccPagination.first}"
action="{!AccPagination.next}"
action="{!AccPagination.previous}"
action="{!AccPagination.last}"
buttons are not working for next or previous records.help me.
In your code 'pageBlockTable' is directly bind to AccList and AccList is only updated when record type is changed.
Need to add a new method 'getAccounts' in controller and bind it to 'pageBlockTable' in vfp.
Make the following changes in code-
1. Update Controller -
public class RecordTypeAccounts {
public string showaccid { get; set; }
String recType = 'typeId';
public List<Account> AccList {get;set;}
public List<SelectOption> getrectypes() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('typeId','--Select Record Type --'));
for(RecordType rt:[select id,name from RecordType where sobjecttype='Account']){
options.add(new SelectOption(rt.id,rt.name));
}
return options;
}
public String getRecordType() {
return recType;
}
public void setRecordType(String recType) {
this.recType= recType;
}
public ApexPages.StandardSetController AccPagination
{
get{
if(AccPagination== null)
{
AccPagination= new ApexPages.StandardSetController(Database.getQueryLocator([select name,rating,phone from account where recordtypeid =: recType]));
}
return AccPagination;
}
set;
}
Public void getAcclist()
{
AccPagination = null;
AccPagination.setPageSize(5);
// Acclist = AccPagination.getRecords();
}
public List<Account> getAccounts(){
AccPagination.setPageSize(5);
return (List<Account>) AccPagination.getRecords();
}
public PageReference detailPage() {
showaccid = System.currentPageReference().getParameters().get('abc');
PageReference nextPage = new PageReference('/' + showaccid);
nextPage.setRedirect(true);
return nextPage;
}
}
2. Update VFP -
<apex:page controller="RecordTypeAccounts" title="Find the Accounts of corresponding record type" sidebar="False">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="selectedRecordType" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Choose Record Type for Account" for="rt" />
<apex:panelGrid columns="2">
<apex:selectList value="{!RecordType}" multiselect="false" size="1">
<apex:selectOptions value="{!rectypes}"/>
<apex:actionSupport event="onchange" action="{!getAccList}" reRender="Account_list"/>
</apex:selectList>
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!Accounts}" var="item" id="Account_list">
<apex:column value="{!item.name}"/>
<apex:column value="{!item.rating}"/>
<apex:column value="{!item.phone}"/>
<apex:column >
<apex:commandLink value="Click here" action="{!detailPage}">
<apex:param name="abc" value="{!item.id}" />
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
<apex:panelGrid columns="8" id="PanelId">
<apex:commandLink action="{!AccPagination.previous}" rerender="Account_list">
<apex:outputLabel value="<<Previous" style="font-weight: bold;"/>
</apex:commandlink>
<apex:commandLink action="{!AccPagination.next}" rerender="Account_list">
<apex:outputLabel value="Next>>" style="font-weight: bold;"/>
</apex:commandlink>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
</apex:page>
Let me know if any help is required.
If it help you then don't forget to mark it as 'HelpFull'