You need to sign in to do that
Don't have an account?
Caculating count
Hi friends
someone please help me to resolve the following.
Data is stored in the object Travelling__c as,
Place |
userid |
Lasvegas |
0001 |
Florida |
0001 |
California |
0001 |
Florida |
0001 |
Lasvegas |
0001 |
trying to display the the total trips for the user ooo1. In the below format
Trips |
Place |
2 |
Lasvegas |
2 |
Florida |
1 |
California |
Basically here Trips is the count of the trips to each place the User has Travelled.
Here is my VF Page and controller. I am able to display the results for places. I need some help on how to display the Trips Value... Please help..
<apex:page controller="TravellingSummary" >
<apex:form >
<apex:pageBlock><br />
<font face="Arial" size="3"><b> Below summarizes your Total Trips:</b></font><br /><br /><br />
<apex:pageBlockTable value="{!Summary}" var="summ">
<!-- <apex:column headervalue="Trips">
<apex:outputtext value="1"></apex:outputtext>
</apex:Column> -->
<apex:column headervalue="Place">
<apex:outputtext value="{!summ.place__c}"></apex:outputtext>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons location="Bottom" >
<apex:commandButton action="{!save}" value="Submit"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class TravellingSummary
{
public List<Travelling__c> tve;
public PageReference cancel() {
return null;
}
public PageReference save() {
return null;
}
public List<Travelling__c> getSummary()
{
tve=[Select Place from Travelling__c where user_ID__c=:UserInfo.getUserId()];
return tve;
}
}
I see that you did not use the visualforce page that I have included in my first response. Please indent your code. It will help you a lot, if you read it at a later time (I got that impression from the visualforce code that you have pasted in the code block!).
All Answers
<apex:page controller="TravellingSummary" >
<apex:form >
<apex:pageBlock><br />
<font face="Arial" size="3"><b> Below summarizes your Total Trips:</b></font><br /><br /><br />
<apex:pageBlockTable value="{!Summary}" var="summ">
<apex:column headervalue="Trips">
<apex:outputtext value="{!Summ.Total"></apex:outputtext>
</apex:Column>
<apex:column headervalue="Place">
<apex:outputtext value="{!summ.Place}"></apex:outputtext>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons location="Bottom" >
<apex:commandButton action="{!save}" value="Submit"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class TravellingSummary
{
private Map<String, PlaceSummary> mapSums = new Map<String, PlaceSummary>();
public PageReference cancel()
{
return null;
}
public PageReference save()
{
return null;
}
public List<PlaceSummary> getSummary()
{
for (Travelling__c t : [Select Place from Travelling__c
where user_ID__c=:UserInfo.getUserId()
order by Place])
{
if (!mapSums.containsKey(t.Place))
mapSums.put(t.Place, new PlaceSummary());
PlaceSummary s = mapSums.get(t.Place);
s.Place = t.Place;
s.Total += 1;
}
return mapSums.values();
}
public class PlaceSummary
{
public Integer Total {get;set;}
public String Place {get; set;}
static
{
Total = 0;
}
}
}
Please test the above code and fix any syntax errors. I just typed the above into this code block.
Hope this helps.
Hi venkat ..
Thanks for the solution.
I am getting few compile errors..
Error: Compile Error: unexpected token: static at line 51 column 1
Any idea why this is happening????
public class TravellingSummary
{
private Map<String, PlaceSummary> mapSums = new Map<String, PlaceSummary>();
public PageReference cancel()
{
return null;
}
public PageReference save()
{
return null;
}
public List<PlaceSummary> getSummary()
{
for (Travelling__c t : [Select Place__c from Travelling__c
where user_ID__c=:UserInfo.getUserId()
order by Place])
{
if (!mapSums.containsKey(t.Place__c))
mapSums.put(t.Place__c, new PlaceSummary());
PlaceSummary s = mapSums.get(t.Place__c);
s.Place = t.Place__c;
s.Total += 1;
}
return mapSums.values();
}
public class PlaceSummary
{
public Integer Total {get;set;}
public String Place {get; set;}
static
{
Total = 0;
}
}
}
Sorry about that. You cannot have static initializers in inner classes.
public class Travelling { private Map<String, PlaceSummary> mapSums = new Map<String, PlaceSummary>(); public PageReference cancel() { return null; } public PageReference save() { return null; } public List<PlaceSummary> getSummary() { for (Travelling__c t : [select Place__c from Travelling__c where user_ID__c = :UserInfo.getUserId() order by Place__c]) { if (!mapSums.containsKey(t.Place__c)) mapSums.put(t.Place__c, new PlaceSummary(0)); PlaceSummary s = mapSums.get(t.Place__c); s.Place = t.Place__c; s.Total += 1; } return mapSums.values(); } public class PlaceSummary { public Integer Total {get;set;} public String Place {get; set;} public PlaceSummary(Integer t) { this.Total = t; } } }
Venkat - sorry for the trouble. Still i get the below error.
Error: Unknown property 'PlaceSummary.Place__c'
Does it give a line number? . I do not get any error when I save it on my sand box. Are you on Spring '09.
Please post your class as well as the visualforce page. Please use the code block to post code.
No. It did not give the line number.
I am also trying this in sandbox.
<apex:page controller="TravellingSummary" > <apex:form > <apex:pageBlock><br /> <font face="Arial" size="3"><b> Below summarizes your Total Trips:</b></font><br /><br /><br /> <apex:pageBlockTable value="{!Summary}" var="summ"> <apex:column headervalue="Trips"> <apex:outputtext value="{!summ.Total>"</apex:outputtext> </apex:Column> <apex:column headervalue="Place"> <apex:outputtext value="{!summ.Place__c}"></apex:outputtext> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons location="Bottom" > <apex:commandButton action="{!save}" value="Submit"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
public class TravellingSummary { private Map<String, PlaceSummary> mapSums = new Map<String, PlaceSummary>(); public PageReference cancel() { return null; } public PageReference save() { return null; } public List<PlaceSummary> getSummary() { for (Travelling__c t : [select Place__c from Travelling__c where user_ID__c = :UserInfo.getUserId() order by Place__c]) { if (!mapSums.containsKey(t.Place__c)) mapSums.put(t.Place__c, new PlaceSummary(0)); PlaceSummary s = mapSums.get(t.Place__c); s.Place = t.Place__c; s.Total += 1; } return mapSums.values(); } public class PlaceSummary { public Integer Total {get;set;} public String Place {get; set;} public PlaceSummary(Integer t) { this.Total = t; } } }
I see that you did not use the visualforce page that I have included in my first response. Please indent your code. It will help you a lot, if you read it at a later time (I got that impression from the visualforce code that you have pasted in the code block!).
Hi Venkat
Many Thanks for all the help in solving this....
I got where i was doing wrong...
Thanks again....