Hi there I have the following code that needs to be added to a map so I can pull the Sum of the Unit Price Quote Currency by the key Equipment Type. How can I conform an aggregate results SOQL query into a map? I need to do this because the sum cannot be subscripted in apex. Below is my apex and visualforce code.
private String queryConstructorAgg() { String query_string = 'SELECT SUM (Unit_Price_Quote_Currency__c) unitpricequotecurrency, '; //create a string and select the min Beacon Reference ID and call it beaconReference List<String> query_fields = new List<String>(); if (MultiQuoteConfigurations.Group_by_Arr_Airport__c) query_fields.add('Ending_Point_Airport__r.Name endingPointAirportName'); if (MultiQuoteConfigurations.Group_by_Delivery__c) query_fields.add('Ending_Point_City__c, Ending_Point_Postcode__c, Ending_Point_Country__c'); if (MultiQuoteConfigurations.Group_by_Dep_Airport__c) query_fields.add('Starting_Point_Airport__r.Name startingPointAirportName'); if (MultiQuoteConfigurations.Group_by_Pickup__c) query_fields.add('Starting_Point_City__c, Starting_Point_Postcode__c, Starting_Point_Country__c'); if (MultiQuoteConfigurations.Group_by_POD__c) query_fields.add('Ending_Point_Seaport__r.Name endingPointSeaportName'); if (MultiQuoteConfigurations.Group_by_POL__c) query_fields.add('Starting_Point_Seaport__r.Name startingPointSeaportName'); //create a new string called query fields //If the checkbox for the grouping = true, then add the field following it. For example, if Group By Airport is true, then add the Ending Airport name to the string query_string += String.join(query_fields, ', '); query_string += ' FROM OpportunityLineItem WHERE OpportunityID = :OpportunityId'; // concatenate the list with commas // concatenate the list with the following parameter of FROM OpportunityLineITem where OpportunityID = :OpportunityID query_string += ' GROUP BY '; List<String> group_fields = new List<String>(); if (MultiQuoteConfigurations.Group_by_Arr_Airport__c) group_fields.add('Ending_Point_Airport__r.Name'); if (MultiQuoteConfigurations.Group_by_Delivery__c) group_fields.add('Ending_Point_City__c, Ending_Point_Postcode__c, Ending_Point_Country__c'); if (MultiQuoteConfigurations.Group_by_Dep_Airport__c) group_fields.add('Starting_Point_Airport__r.Name'); if (MultiQuoteConfigurations.Group_by_Pickup__c) group_fields.add('Starting_Point_City__c, Starting_Point_Postcode__c, Starting_Point_Country__c'); if (MultiQuoteConfigurations.Group_by_POD__c) group_fields.add('Ending_Point_Seaport__r.Name'); if (MultiQuoteConfigurations.Group_by_POL__c) group_fields.add('Starting_Point_Seaport__r.Name'); query_string += String.join(group_fields, ', '); //take the final query string we created before and concatenate with GROUP BY //If the Group By checkbox is true, then add the following field return query_string; } //return the final string which would be something like this SELECT Min (Beacon_Reference_ID)... from OpportunityLineItem WHERE OpportunityID = :OpportunityID GROUP BY ... private List<Item> convertItems(List<AggregateResult> aggregate_line_items) { //create a list called convertItems and pass through a list called aggregate_line_items List<Item> line_items = new List<Item>(); //create a list called line_items for (AggregateResult item : aggregate_line_items) { //loop through the list of aggregate_line_items Item single_line_item = new Item(); //create a new items called single_line_item single_line_item.unitpricequotecurrency = (Double)item.get('unitpricequotecurrency'); //Add the beaconReference to the single_line_item if (MultiQuoteConfigurations.Group_by_POL__c) { single_line_item.Starting_Point_Seaport_Name = (String)item.get('startingPointSeaportName'); //if checkbox GROUP by POL is marked then pull the starting Point Seaport name into the single_line_item item } if (MultiQuoteConfigurations.Group_by_POD__c) { single_line_item.Ending_Point_Seaport_Name = (String)item.get('endingPointSeaportName'); //if checkbox GROUP by POL is marked then pull the ending Point Seaport name into the single_line_item item } if (MultiQuoteConfigurations.Group_by_Dep_Airport__c) { single_line_item.Starting_Point_Airport_Name = (String)item.get('startingPointAirportName'); //if checkbox GROUP by POL is marked then pull the starting Point Airport name into the single_line_item item } if (MultiQuoteConfigurations.Group_by_Arr_Airport__c) { single_line_item.Ending_Point_Airport_Name = (String)item.get('endingPointAirportName'); //if checkbox GROUP by POL is marked then pull the Ending Point Airport name into the single_line_item item } if (MultiQuoteConfigurations.Group_by_Delivery__c) { single_line_item.Ending_Point_City = (String)item.get('Ending_Point_City__c'); single_line_item.Ending_Point_Postcode = (String)item.get('Ending_Point_Postcode__c'); single_line_item.Ending_Point_Country = (String)item.get('Ending_Point_Country__c'); populateDelivery(single_line_item); //if GROUP by Delivery is marked, then add ending point city, postcode and country } if (MultiQuoteConfigurations.Group_by_Pickup__c) { single_line_item.Starting_Point_City = (String)item.get('Starting_Point_City__c'); single_line_item.Starting_Point_Postcode = (String)item.get('Starting_Point_Postcode__c'); single_line_item.Starting_Point_Country = (String)item.get('Starting_Point_Country__c'); populatePickup(single_line_item); //if GROUP by Pickup is marked, then add ending point city, postcode and country } line_items.add(single_line_item); //Add all the above to the line_items list created befiore } return line_items; //return all the items in the line items list
Visualforcepage code
<apex:outputText rendered="{!IF(MultiQuoteConfigurations.Single_Reference__c,false,true)}"> <apex:repeat value="{!OverallListOfUnits}" var="unit"> <td>{!item.unitpricequotecurrency[unit]}</td> </apex:repeat> </apex:outputText>
Visualforce page error: Expression of type Number cannot be subscripted.
Can you edit your post and use the code format markup button </> so it's readable?
private String anExample;