You need to sign in to do that
Don't have an account?

Product Family???
Hi all:
I have an issue where I am getting a Subtotal on a product family but my code is hard coded with the product family.
Now if the admin adds another product family I would have to go back to the code and hard code that family...
Is there an easier way to do the following:
quote = [Select s.Opportunity__r.Pricebook2Id, Quote_Amount_rollup__c, LastmodifiedDate,Decimal__c, (Select Unit_Price__c, Unit_Net_Price__c, ServiceDate__c, Sales_Discount__c, Quote__c, Qty_Ordered__c, Product2__c, Product2__r.Name, Product2__r.Family,Name, Id, Ext_Price__c, Ext_Net_Price__c, Ext_Price_tmp__c, Description__c From Quote_Lines__r order by name ), (Select Title, Body, CreatedDate From Notes), s.Opportunity__r.HasOpportunityLineItem, s.Opportunity__r.Sub_Partner__c, s.Opportunity__r.Name, s.Name,s.Partner_Direct__c, s.Opportunity__r.Id, s.Opportunity__r.License__c,s.Opportunity__c,s.Valid_Until__c From SFDC_520_Quote__c s where s.id = :id limit 1]; quoteLineItems = quote.Quote_Lines__r; for ( SFDC_520_QuoteLine__c ql : quoteLineItems ) { if(ql.Product2__r.Family=='ABC'){ sumSub += ql.Ext_Net_Price__c; } if(ql.Product2__r.Family=='CDE'){ sumSub2 += ql.Ext_Net_Price__c; } }
Thanks
Happy New Year
How about using a Map to store the sums, with the index being the Product Family name.
Something like this (untested):
quote = [Select s.Opportunity__r.Pricebook2Id, Quote_Amount_rollup__c, LastmodifiedDate,Decimal__c, (Select Unit_Price__c, Unit_Net_Price__c, ServiceDate__c, Sales_Discount__c, Quote__c, Qty_Ordered__c, Product2__c, Product2__r.Name, Product2__r.Family,Name, Id, Ext_Price__c, Ext_Net_Price__c, Ext_Price_tmp__c, Description__c From Quote_Lines__r order by name ), (Select Title, Body, CreatedDate From Notes), s.Opportunity__r.HasOpportunityLineItem, s.Opportunity__r.Sub_Partner__c, s.Opportunity__r.Name, s.Name,s.Partner_Direct__c, s.Opportunity__r.Id, s.Opportunity__r.License__c,s.Opportunity__c,s.Valid_Until__c From SFDC_520_Quote__c s where s.id = :id limit 1]; quoteLineItems = quote.Quote_Lines__r; Map<String,Double> FamilySumMAP = new Map<String,Double>(); for ( SFDC_520_QuoteLine__c ql : quoteLineItems ) { if(FamilySumMap.containsKey(ql.Product2__r.Family) { Double tmpSum = FamilySumMap.get(ql.Product2__r.Family)+ql.Ext_Net_Price__c; FamilySumMap.put(ql.Product2__r.Family,tmpSum); }else { FamilySumMap.put(ql.Product2__r.Family,ql.Ext_Net_Price__c); } }
You will end up with a Map that has for its index every unique Family name, and this is safe from any changes where new ones are added.
Then you can query the map by the family name key with the get method in order to get the final sum value.
Awesome Thank you...
Now when you say query the map do you mean:
for(SFDC_520_QuoteLine__c gttl:[select Product2__r.Family, Ext_Net_Price__c from SFDC_520_QuoteLine__c where Product2__r.Family in :FamilySumMap.keyset()]) {
sumSub=FamilySumMap.get('tmpSum'); }
But I still do not know how to place in the subtotal on my VF page or get the subtotals for each Product_Family?
In my VF Page I did the following:
<apex:outputLabel value="SubTotal " rendered="{!item.Product2__r.Family}=='ABC'"/> <apex:outputLabel value="{!sumSub}"/> <apex:outputLabel value="SubTotal CDE " rendered="{!item.Product2__r.Family}=='CDE'"/> <apex:outputLabel value="{!sumSub}"/>
Thanks
Happy New Year!!
Yes, you query the map with the get method, you don't need to use the tmpsum though, that is just a placeholder.
It would just be something like:
Double mydoubleABC = FamilySumMAP.get('ABC');
For your Visualforce, it really depends on what you are trying to do. You could use the repeat tag to move through the index list to get your family names, then query the subtotals out. I would have to think about it more to provide an example, but I am sure it could be done.
Happy New Year!
That is awesome and it worked... But I really do not want to hardcode the family in but I tried this and it does not work
List<Product2> accs = [SELECT Family FROM Product2];for(SFDC_520_QuoteLine__c gttl:[select Product2__r.Family, Ext_Net_Price__c from SFDC_520_QuoteLine__c where Product2__r.Family in :FamilySumMap.keyset()]) { for(integer i=0; i<accs.size(); i++) { // sumSub = FamilySumMAP.get('ABC'); // sumSub2 = FamilySumMAP.get('CDE'); sumSub[i] = FamilySumMap.get('accs[i].Family'); }}
What am I doing wrong?
I am trying to get all the family Names from product and then incrementing in where sumSub1,sumSub2 is equivalent to a family.
Thanks
Happy Happy Newwww YEARRRRRRRRRRRRRRRR
MMA_FORCE, you are having the same issue as mmaxtra, that is an odd coincidence.
Anyway, neither of you should need to hardcode the family names. Assuming you only want to display the ones that have values anyway, this what I would do.
Create a wrapper class to put the name and the sum in the same "record" then create a list of these records to display on your page.
Your updated apex would look like this:
quote = [Select s.Opportunity__r.Pricebook2Id, Quote_Amount_rollup__c, LastmodifiedDate,Decimal__c, (Select Unit_Price__c, Unit_Net_Price__c, ServiceDate__c, Sales_Discount__c, Quote__c, Qty_Ordered__c, Product2__c, Product2__r.Name, Product2__r.Family,Name, Id, Ext_Price__c, Ext_Net_Price__c, Ext_Price_tmp__c, Description__c From Quote_Lines__r order by name ), (Select Title, Body, CreatedDate From Notes), s.Opportunity__r.HasOpportunityLineItem, s.Opportunity__r.Sub_Partner__c, s.Opportunity__r.Name, s.Name,s.Partner_Direct__c, s.Opportunity__r.Id, s.Opportunity__r.License__c,s.Opportunity__c,s.Valid_Until__c From SFDC_520_Quote__c s where s.id = :id limit 1]; quoteLineItems = quote.Quote_Lines__r; Map<String,Double> FamilySumMAP = new Map<String,Double>(); for ( SFDC_520_QuoteLine__c ql : quoteLineItems ) { if(FamilySumMap.containsKey(ql.Product2__r.Family) { Double tmpSum = FamilySumMap.get(ql.Product2__r.Family)+ql.Ext_Net_Price__c; FamilySumMap.put(ql.Product2__r.Family,tmpSum); }else { FamilySumMap.put(ql.Product2__r.Family,ql.Ext_Net_Price__c); } } public FamilySumc { String Famname {set; get;} Double FamSum {set; get;} FamilySumc(String n,Double s){ this.Famname=n; this.FamSum=s; } } List<FamilySumc> Familys = new List<FamilySumc>(); for(String x: FamilySumMap.keySet()){ Familys.add(new FamilySumc(x,FamilySumMap.get(x))); }
And your Visualforce would be something like this:
<apex:repeat value="{!Familys}" var="F" id="idFams"> <apex:outputLabel value="SubTotal {!F.Famname}" /><br/> <apex:outputText value="{!F.FamSum}" id="theValue"/> </apex:repeat>
You might need to tweak the formatting a little.
Anyway, hope this helps you both out.
Happy New Year!!!
Awesome but I get an error on unexpected token public????
void queryQuoteLines(id id) {
quote = [Select s.Opportunity__r.Pricebook2Id, Quote_Amount_rollup__c,LastmodifiedDate,Decimal__c,
(Select Unit_Price__c, Unit_Net_Price__c, ServiceDate__c,
Sales_Discount__c,
Quote__c, Qty_Ordered__c, Product2__c, Product2__r.Name,
Product2__r.Family,Name,
Id, Ext_Price__c,
Ext_Net_Price__c, Ext_Price_tmp__c, Description__c From Quote_Lines__r
order by name ),
(Select Title, Body, CreatedDate From Notes),
s.Opportunity__r.HasOpportunityLineItem, s.Opportunity__r.Sub_Partner__c,
s.Opportunity__r.Name, s.Name,s.Partner_Direct__c,
s.Opportunity__r.Id, s.Opportunity__r.License__c,s.Opportunity__c,s.Valid_Until__c
From SFDC_520_Quote__c s
where s.id = :id limit 1];
a3months = quote.lastmodifieddate;
a3months = a3months.addMonths(3);
quoteLineItems = quote.Quote_Lines__r;
nts=quote.Notes;
rsl =[Select Name, License__c from Reseller__c where Name=:quote.Partner_Direct__c];
sumSub=0.0;
Map<String,Double> FamilySumMAP = new Map<String,Double>();
for ( SFDC_520_QuoteLine__c ql : quoteLineItems )
{
ql.Ext_Price_tmp__c = ql.Ext_Net_Price__c;
if ( ql.Sales_Discount__c == null )
{
ql.Sales_Discount__c = 0.0;
}
if(FamilySumMap.containsKey(ql.Product2__r.Family))
{
tmpSum = FamilySumMap.get(ql.Product2__r.Family)+ql.Ext_Net_Price__c;
FamilySumMap.put(ql.Product2__r.Family,tmpSum);
}else
{
FamilySumMap.put(ql.Product2__r.Family,ql.Ext_Net_Price__c);
}
}
Thanks...
Also my VF Page that I am working on is in this thread:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=19992
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=19992