You need to sign in to do that
Don't have an account?
Max_g
List index out of bounds: 0
I have a VF page that is using a datatable. When I get to 50 rows, I am getting the error message. How do I code for additional rows, or can I set the number of rows to be displayed on the page ?
Need I explain?
Besides this, I highly agree that you shouldn't do soql inside an iteration. Even if you consider it unlikly to hit a governer limit in your organisation, it is still terribly inefficient.
All Answers
You limit the rows on the page by setting the "Rows" attribute to the <apex:datatable/>
or else use Standard Set Controller to set the page size in the apex class
Recent release is support OFFSET in the SOQL queries.
You can use either one of teh above options based on your requirement.
Added rows = 100 to my datatale.
Still got the error.
Error is on record 38
here is the code for my VF page and controller.
public with sharing class UsrAcct {
public PageReference Cancel() {
return null;
}
Public string newname = Apexpages.currentpage().getparameters().get('id2');
List<Account> Accounts;
public List<Account> getAccounts() {
string UserId=UserInfo.getUserId();
system.debug('User Id = ' + Userid);
Id id = ApexPages.currentPage().getParameters().get('id');
system.debug('Apex Id = ' + id);
system.debug('Apex NewName = ' + newname);
if(id == null) id = Userid;
if(Accounts== null) Accounts = [Select id,name, Current_YTD_Sales__c,Owner_Name__c,SHCOMP_ID__c from Account where OwnerId = :id and Current_YTD_Sales__c != 0 order by name];
if(Accounts.size() > 0) accounts[0].Owner_Name__c = newname;
for (Integer i=0; i<Accounts.size(); i++) {
ID SHAID = Accounts[i].id;
list<Sales_History_Comp__c > SHCID = [select id from sales_History_Comp__c where Account__c = :SHAID];
accounts[i].SHCOMP_ID__C = SHCID[0].id;}
system.debug('Accounts to return = ' + Accounts);
return Accounts;
}
public pagereference slct()
{
String selectedTask = System.currentPageReference().getParameters().get('moveid');
String selectedName = System.currentPageReference().getParameters().get('SLCTNAME');
String selectedSHC = System.currentPageReference().getParameters().get('SHCID');
system.debug('Selected name = ' + selectedName);
system.debug('Selected id = ' + selectedTask);
system.debug('Selected SHCid = ' + selectedSHC);
String uid=ApexPages.currentPage().getParameters().get('id');
system.debug('UID = ' + uid);
PageReference newURL=new PageReference('/apex/Sales_History_Comparison');
newURL.getParameters().put('id',selectedSHC);
newURL.getParameters().put('id2',selectedName);
newURL.setRedirect(true);
system.debug('NEWURL = ' + NewURL);
return newURL;
}
public pagereference redirectfun()
{
string str=userinfo.getuserid();
PageReference newURL=new PageReference('/apex/Manager_Inquiry');
newURL.getParameters().put('id',str);
newURL.setRedirect(true);
return newURL;
}
}
VF Page
<apex:page Controller="UsrAcct" id="MyAccounts">
<!-- Created by: Max Gilbert Last Update: June 29 2012 SFDC --> <apex:pageBlock title="List of Accounts for {!$User.FirstName} {!$User.LastName} "> </apex:pageBlock> <apex:pageBlock title="My Accounts with balances this year "> <apex:form > <apex:dataTable value="{!Accounts}" var="Accts" id="MyAccounts" cellPadding="4" border="1" rows="100"> <apex:column > <apex:facet name="header">Action</apex:facet> <apex:commandLink action="{!slct}" value="Select" style="fontWeight:bolder" id="ReplyLink" onclick="" > <apex:param name="moveid" value="{!Accts.Id}"/> <apex:param name="SLCTNAME" value="{!Accts.name}"/> <apex:param name="SHCID" value="{!Accts.SHCOMP_ID__c}"/> </apex:commandLink> </apex:column> <apex:column headervalue="Account Name"> <apex:outputText value="{!Accts.name}"/> </apex:column> <apex:column headervalue="YTD Sales"> <!-- <apex:outputText value="{!Accts.Current_YTD_Sales__c}"/> --> <apex:outputText style="float:right" value="{0, number, ,000}">
<apex:param value="{!Accts.Current_YTD_Sales__c}" /> </apex:outputText>
</apex:column> </apex:dataTable> <apex:commandButton value="Return" action="{!Cancel}"/> </apex:form> </apex:pageBlock> </apex:page>
What exactly are you trying to achieve in the getAccounts method. It is not best pratcise to write the queries inside for loop.
Can you explain your object model and wht you are trying to achieve.
Need I explain?
Besides this, I highly agree that you shouldn't do soql inside an iteration. Even if you consider it unlikly to hit a governer limit in your organisation, it is still terribly inefficient.