title: Grouped by Reference Field SQQL Salesforce
body: <p>I am about to make a <strong>GROUP BY</strong>  with reference fields in a <strong>SOQL Apex Salesforce</strong> query, i  get the following message : <em><strong>the field can not be grouped in a query call</strong></em></p>
  <p>The solution i  have is to create  custom fields and update them with a process builder but this solution will help only for the new records and i will have to update all the existing records in the database(more than 1 Million) to fill these custom fields newly created.</p>
  <p>What can i can to create a <strong>Group By</strong> with reference field from a parent?</p>
  <p>Here is my query:</p>
  <pre><code>SELECT Delivery__r.Beneficiaire__r.ASPO_Master__r.Name, Delivery__r.Beneficiaire__r.ASPO_Master__r.New_ID__c, UM__c,  SUM(Quantity__c)qty 
  FROM Item_Distributed__c
  WHERE Quantity__c !=0 AND Delivery__r.Beneficiaire__r.ASPO_Master__c !=''
  AND Del_Status__c='Delivered'
  AND Product__c IN :articleContainersId                                        
  GROUP BY  Delivery__r.Beneficiaire__r.ASPO_Master__r.Name, Delivery__r.Beneficiaire__r.ASPO_Master__r.New_ID__c, UM__c];
  </code></pre>
  <p>I want to notice that the query is made on a custom object Called Item_Distributed__c with a parent called Delivery which is a child of Account. The field i want to query are from Account.</p>