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
Kenn K.Kenn K. 

Update Object with unique values from Child object using Aggregate result

I am trying to update a field on the Quote (Operational_Start_Date__c) from the results of an aggregate result query.
The trigger runs on quote, queries QuoteLine for unique values and update the Quote with the unique values. This is what I have so far but it doesn't seem to be working;
 
trigger SB_QuoteAdditionalUpdates on SBQQ__Quote__c (before insert, before update) {
	
    	
    	Set<Id> quoteIds = new Set<Id>();
    
   		 for (SBQQ__Quote__c quotes : Trigger.new) {
   		 	
   		 		quoteIds.add(quotes.id);
   		 
   		 }
    	
    		List<AggregateResult> uniqueCountries = ([SELECT  Country_Operational_Date__c FROM SBQQ__QuoteLine__c WHERE SBQQ__Quote__c IN:quoteIds 
	    												AND country_code__c <> null AND Employee_CountFormula__c <> null GROUP BY Country_Operational_Date__c]);
    		
    		
    		if(uniqueCountries.Size()>0 ){
    			
    			
    			for (AggregateResult uniqueCountry : uniqueCountries){
    				
    				quotes.Operational_Start_Date__c = String.valueOf(uniqueCountry.get('Country_Operational_Date__c'));
    				system.debug('======>'+String.valueOf(uniqueCountry.get('Country_Operational_Date__c')));
    				
    			}      			
    		}
   		 
}



When I make the for loop run through the aggregate result (not optimized/bulkified), it updates the quote but it's only updating with one of the unique values and the quote might have had 3 unique values.
KevinPKevinP
Your for loop at the end, is overwritting the single quote line.