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
Chanagan SakulteeraChanagan Sakulteera 

How to fix this error "Illegal assignment from LIST<AggregateResult>".

Hi all,
I want to know how to fix this error  "Illegal assignment from LIST<AggregateResult> to SOBJECT:Product_Service__c"
thsi is a code 
interFlight = [select sum(Total_Cost__c) from Product_Service__c where Product_Service_Type__c = 'Air Ticket - International' and id =: productId];

Many thank in advance :)))
Anoop yadavAnoop yadav
PratikPratik (Salesforce Developers) 
Hi Chanagan,

Can you please tell me the type of variable "interFlight

The query you have has aggregated function sum(Total_Cost__c).

Here is the sample code:


AggregateResult[] groupedResults
  = [SELECT AVG(Amount)aver FROM Opportunity];
Object avgAmount = groupedResults[0].get('aver');

Thanks,
Pratik