function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Girbson Bijou 8Girbson Bijou 8 

only aggregate expressions use field aliasing

Hi  All, I want group record by the  field named Shipment_Status__c  as attached.  I get the error "only aggregate expressions use field aliasing"
Here the controller
public class ContainerGlobalShipmentController{
public Map<String, List<Container__c>> Records { get; set; }
public ContainerGlobalShipmentController() {
 Records = new Map<String, List<Container__c>>();
 Container__c [] results =
[SELECT  Shipment_Status__c status, Pkl__c, PO__c, Invoice__c,Name, Size_in_feet__c, Description__c, 
Bill_of_Lading__c,On_Wharf_Date__c,Sailing__c,ETA__c,Demurrage_begins__c,
Brocker__c,Comments__c,     ID_Container__c,  Consignee__c, Provenance__c
 FROM Container__c WHERE (Departed_to_Wharf_Date__c = NULL OR 
 (Departed_to_Wharf_Date__c =LAST_N_DAYS:5))   
 AND Provenance__c ='FFP FLORIDA'];
 
  for(Container__c result: results) {
     status = (String)result.get('status');
    if(!Records.containsKey(status)) {
      Records.put(status, new Container__c[0]);
    }
    Records.get(status).add(result);
  }
}
}

User-added image
Best Answer chosen by Girbson Bijou 8
Alain CabonAlain Cabon
Hi,

There is no "group by" in your request.

[SELECT Shipment_Status__c status,

for(Container__c result: results) { status = result.Shipment_Status__c ;
 

All Answers

Alain CabonAlain Cabon
Hi,

There is no "group by" in your request.

[SELECT Shipment_Status__c status,

for(Container__c result: results) { status = result.Shipment_Status__c ;
 
This was selected as the best answer
Girbson Bijou 8Girbson Bijou 8
Thank you  Alain. It work as expected. Now i want add a donut chart with total of the record group by Shipment_Status__c. How can you help?
//Controller
public class ContainerGlobalShipmentController{
    public String Account { get; set; }
    public Map<String, List<Container__c>> Records { get; set; }
    public ContainerGlobalShipmentController() {
     
	 Records = new Map<String, List<Container__c>>();
     Container__c [] results = [SELECT  Shipment_Status__c , Shipper__r.Name__c , Pkl__c, PO__c, Invoice__c,Name, Size_in_feet__c, Description__c, 
                            Bill_of_Lading__c,On_Wharf_Date__c,Sailing__c,ETA__c,Demurrage_begins__c,Brocker__c,Comments__c,     ID_Container__c,  Consignee__c, Provenance__c
                            FROM Container__c    
							WHERE (Departed_to_Wharf_Date__c = NULL OR 
                               (Departed_to_Wharf_Date__c =LAST_N_DAYS:5))   
                             AND Provenance__c ='FFP FLORIDA'];
 
      for(Container__c result: results) {
			String status = result.Shipment_Status__c ;
			if(!Records.containsKey(status)) {
			 Records.put(status, new Container__c[0]);
            }
      Records.get(status).add(result); 
      }
    }
}


//the body of the visualforce is:
<table style="width:100%;border-collapse: collapse; border: 0.1px solid black;"> 
 <tr> 
	 <th>System Code</th> 
	 <th>Ref#</th> 
	 <th>Lead/PO</th>
	 <th>Invoice#</th>
 </tr> 
 <apex:repeat var="key" value="{!Records}"> 
   <tr><th style="background: Gray; color:white; text-transform:uppercase;"><b> {!key}</b></th>     
  </tr>
  <apex:repeat value="{!Records[key]}" var="c">
   <tr>
		 <td>{!c.ID_Container__c}</td>
		 <td>{!c.Pkl__c}</td>
		 <td>{!c.PO__c}</td>
		 <td>{!c.Invoice__c}</td>
 </tr>
  </apex:repeat>
 </apex:repeat>
 </table>

 
kali sujan chakravarthykali sujan chakravarthy
Dear All, I'm creating the Search button once the button is  pressed the records should display from that object.

Compile Error:Error: Compile Error: only aggregate expressions use field aliasing at line 17 column 12

public with sharing class TrainingDealAfterButtonClick{

    public string EnteredText{get;set;}
 
 public List<Training_Deal__c>TDlist{get;set;}
 

    public Boolean showsection1{get;set;}

    public PageReference SearchResult()
    
    {
        
      line 17---  TDlist = [SELECT Name,Course__r.Course_Name__c,Deal_Risk_Status__c, Discount_Percentage__c, 
        
               Fees_Finalised_For_student__c,Fee_paid_by_student__c,Fees_Pending_By_Student__c
                
                Trainer_Appointed__r.First_Name__c FROM Training_Deal__c
                
                WHERE Course__r.Course_Name__c LIKE : '%'+EnteredText + '%'];
    
    if(TDlist.isempty()==true)
    {
        ApexPages.Message errormessage = new ApexPages.Message(ApexPages.Severity.ERROR,'No Records Found');
        ApexPage.addMessage(errormessage);
    }
    else
    {
        showsection1=true;
    }
        return null;
    }
}
 

VFP:

<apex:page controller="TrainingDealAfterButtonClick">
<apex:form>
    <apex:ouputlabel style = "font=weight:bold" value ="Enter Course to Search : =">
    </apex:outputlabel>

    <apex:inputText value = "{!EnteredText}"/>
        <apex:commandButton Value="search" action="{!SearchResult}" reRender="block"/>
    <apex:pageBlock id="block">


    <apex:pageMessages />
        <apex:pageBlockTable Value="{!TDlist}" var="pro" rendered="{!showsection1}">
    
    <apex:column><apex:facet name="header"> Name </apex:facet>{!pro.Name}</apex:column>
    <apex:column><apex:facet name="header"> Course </apex:facet>{!pro.Course__r.Course_Name__c}</apex:column>    
    <apex:column><apex:facet name="header"> Deal Risk Status </apex:facet>{!pro.Deal_Risk_Status__c}</apex:column>
    <apex:column><apex:facet name="header"> Discount Percentage </apex:facet>{!pro.Discount_Percentage__c}</apex:column>
    <apex:column><apex:facet name="header"> Fee Finalised For Student </apex:facet>{!pro.Fees_Finalised_For_student__c}</apex:column>
    <apex:column><apex:facet name="header"> Fees Paid By Student </apex:facet>{!pro.Fee_paid_by_student__c}</apex:column>    
    <apex:column><apex:facet name="header"> Fees Pending by Student </apex:facet>{!pro.Fees_Pending_By_Student__c}</apex:column>
    <apex:column><apex:facet name="header"> Trainer Appointed Name </apex:facet>{!pro.Trainer_Appointed__r.First_Name__c}</apex:column>
    
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>
 
Leon ThanikalLeon Thanikal
Hello kali suja chakravarthy,

You missed a comma between one of the fields that you are trying to query.
The  corrected SOQL statement is as follows:
TDlist = [SELECT Name, Course__r.Course_Name__c, Deal_Risk_Status__c, Discount_Percentage__c, Fees_Finalised_For_student__c, Fee_paid_by_student__c, Fees_Pending_By_Student__c, Trainer_Appointed__r.First_Name__c FROM Training_Deal__c WHERE Course__r.Course_Name__c LIKE : '%'+EnteredText + '%'];
Hope that helps!
 
soniya koppadsoniya koppad
Hi  All, .employeenumber, employee name,rating and button object feilds created .but  I get the error "only aggregate expressions use field aliasing"..pls give solution get a output.

Here the Accountcontroller

public with sharing class AccountController{
  
    @AuraEnabled(cacheable=true)
    public static List <Account> getAccount(){
        
      List<Account> EmployeeList = [Select Employee Number,Employee Name,Rating,Button from Employee__c limit 10];
        
        if(!EmployeeList.isEmpty()){
            system.debug('EmployeeList:'+EmployeeList);
            return EmployeeList;
        }
       return Null;
    }
}