You need to sign in to do that
Don't have an account?
Dixit
HOW TO MAKE A SUMMARY OF RECORDS
Hello!~
I'm having trouble to find the best option to do a summary record with n records of the same type.
Let me explain.
I have a VF with a extension which gives me a list of a custom Object (ex: List<products__c> prods) i have this "products" n times with differents IDs but some with the same model...
So i have a WrapperClass that recives as a parameter a list of products. (Public productWrapper (List<products__c> p))
I want to summarize the quantity of products of the same model.
EX (i get in the list)
ID MODEL QUANTITY
01 A 10
02 B 5
03 C 1
04 A 3
05 A 5
06 B 10
07 C 20
so i want my wrapper class to tell me:
Model A: 18 pieces
Model B: 15 pieces
Model C: 21 pieces
but i don't know how exactly to achieve that...
I know that an AggregateResult list should work but i will group those models for differents parameters and sumarize it as well for those parameters....
Any help?
Thanks.
I'm having trouble to find the best option to do a summary record with n records of the same type.
Let me explain.
I have a VF with a extension which gives me a list of a custom Object (ex: List<products__c> prods) i have this "products" n times with differents IDs but some with the same model...
So i have a WrapperClass that recives as a parameter a list of products. (Public productWrapper (List<products__c> p))
I want to summarize the quantity of products of the same model.
EX (i get in the list)
ID MODEL QUANTITY
01 A 10
02 B 5
03 C 1
04 A 3
05 A 5
06 B 10
07 C 20
so i want my wrapper class to tell me:
Model A: 18 pieces
Model B: 15 pieces
Model C: 21 pieces
but i don't know how exactly to achieve that...
I know that an AggregateResult list should work but i will group those models for differents parameters and sumarize it as well for those parameters....
Any help?
Thanks.
This might be more complicated that it needs to be, but it can easily be expanded for different parameters. I created a subclass to summarize the products, and used a Map to change the quantity of the summary by Model type. The same technique can be used for any field or derived parameter. I also implemented comparable to sort it, because in the page I made it chose a reverse order, and I wanted to ensure a more common sense order.
You'll notice that I use an SOQL query to find the Products__c in my default constructor, but you can obviously change that, and I included a constructor that will take a List of Products__c. Here is the visualforce page:
This could probably be done much quicker by someone with more experience, but this is how I would approach the problem with the knowledge that I will be summarizing other parameters too. If you want to get crazy you can make the summary an abstract class so you can apply it to more than just Products__c, but I think that is out of the scope of the question.
I got it for myself, if anyone has a problem related to this...
I got 3 wrappers (clasification by product, clasification by level, clasification by sytem), i got my list of products and iterate them to see how many clasifications was (in a set<string> of clasifications) in the clasification wrapper i made a list of levels for every clasification (i got different level floors in the products) and then i got a wrapper for every level get a clasification by product.
so i got something like this:
Clasification : Fire
-Level 1:
*Product1(10)
*Product2(5)
*Product3(20)
-Level 2:
*Product1(15)
*Product4(5)
Clasification: Water
-Level 1
*Product 3(44)
*Product 5(11)
......and so.