You need to sign in to do that
Don't have an account?
Sorting a list into three categories
First, thank you all for your help. I am learning quite quickly. But now:
On to the next hurdle:
My recordList returns four values to my apex page. I need to split the recordList into three parts based on the Close_Date__c field.
I then need to return the new list (or 3 new lists?) to my VF page based on the date sort.
So, if the "Close_Date__c" is less than 30 days from today, it goes in one section of the VF page. If it is over 60 days, it goes in another, and anything that is between 30 and 60 goes to the third section.
My question is this: how / where do I sort the list, and how do I return it to the VF page?
My Apex Class:
public class getAllRecords {
public getAllRecords(ApexPages.StandardController Controller) {
}
public Opportunity__c[]getRecordDetail(){
Opportunity__c[]recordList;
recordList = [SELECT Opportunity_Name__c,
Owner__c,
Amount__c,
Close_Date__c
FROM Opportunity__c
WHERE Account__c IN
(SELECT AccountId
FROM User
WHERE username=:UserInfo.getUsername())
ORDER BY Close_Date__c];
return recordList;
}
}
my current setup in VF is like this(I have three identical, but only put in one to keep it short):
<apex:pageBlockSection id="zero30" title="0-30 Days" columns="1">
<apex:PageBlockTable value="{!RecordDetail}" var="records" rowClasses="red1,red2">
<apex:column value="{!records.Opportunity_Name__c}" headerValue="Name" />
<apex:column value="{!records.Owner__c}" headerValue="Owner" />
<apex:column value="{!records.Amount__c}" headerValue="Amount" />
<apex:column value="{!records.Close_Date__c}" headerValue="Due By" />
</apex:pageBlockTable>
</apex:pageBlockSection>
Thanks again in advance.
Hi,
Try the below code snippet as reference:
public class getAllRecords
{
public Opportunity__c[]recordList;
public getAllRecords(ApexPages.StandardController Controller)
{
}
public Opportunity__c[]getRecordDetail()
{
recordList = [SELECT Opportunity_Name__c,
Owner__c,
Amount__c,
Close_Date__c
FROM Opportunity__c
WHERE Account__c IN
(SELECT AccountId
FROM User
WHERE username=:UserInfo.getUsername())
ORDER BY Close_Date__c];
return recordList;
}
public Opportunity__c[]getRecordDetail30days()
{
Opportunity__c[]recordList30days;
if(recordList.size()>0)
{
for(Opportunity__c obj:recordList)
{
if(obj.Close_Date__c.daysBetween(system.today())<30)
{
recordList30days.add(obj);
}
}
}
return recordList30days;
}
public Opportunity__c[]getRecordDetail60days()
{
Opportunity__c[]recordList60days;
if(recordList.size()>0)
{
for(Opportunity__c obj2:recordList)
{
if(obj2.Close_Date__c.daysBetween(system.today())<60)
{
recordList60days.add(obj2);
}
}
}
return recordList60days;
}
public Opportunity__c[]getRecordDetaildaysbet30and60()
{
Opportunity__c[]recordList30to60days;
if(recordList.size()>0)
{
for(Opportunity__c obj3:recordList)
{
if(obj3.Close_Date__c.daysBetween(system.today())<60 && obj3.Close_Date__c.daysBetween(system.today())>30)
{
recordList30to60days.add(obj3);
}
}
}
return recordList30to60days;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
This solution looks good, but I am having problems with null references.
if(recordList.size()>0) {
The error occurs with the above line of code. So, is my recordList null? If so, is it trying to call the records from the recordList prior to the select statement populating my list? OR could it be I need to instantiate a new instance of the recordList in each method?
I think the problem as I am seeing it more lies in the recordDetail not getting called. therefore the recordList is not populated. So, now I just need to find a way to do that onLoad of the page. Hmm ... more google-ing ...
:(
Thoughts? Thanks!