You need to sign in to do that
Don't have an account?

fetching result from AggregateResult : soql
i am trying to fetch fields from a aggregteresult but it is giving me error :Invalid field Time_Account_Mapping__c for SObject AggregateResult
Thanks
Time__c tes = [select Time_Account_Mapping__c from Time__c order by LastModifiedById desc limit 1]; AggregateResult obj = [Select Time_Account_Mapping__c,sum(Hours__c) from time__c group by Time_Account_Mapping__c having Time_Account_Mapping__c in (:tes.Time_Account_Mapping__c)]; Account ppla = new Account(); ppla.id = obj.Time_Account_Mapping__c; ppla.Total_Client_Hour__c=obj.sum(Hours__c); // ppla.Total_Client_Hour__c = test.Unknown_Field__1; update ppla;Help me out here.
Thanks
Account acc = new Account();
acc.id= ((ID)obj.get('Time_Account_Mapping__c'));
acc.Total_Client_Hour__c =((decimal)obj.get('sumofhour')) ;
update acc;
All Answers
tried it already giving me error : Method does not exist or incorrect signature: [List<AggregateResult>.get(String)
and i would like to know how can i use sum(hours__c) , because when i am trying to execute this query in workbench it is giving me result under unkown_field__1 section
Error:
Variable does not exist: Time_Account_Mapping__c
do you have any link to fetch the variables from aggregateresult ?
You can get the result either by the alias name or the name 'expr<n>'.
Account acc = new Account();
acc.id= ((ID)obj.get('Time_Account_Mapping__c'));
acc.Total_Client_Hour__c =((decimal)obj.get('sumofhour')) ;
update acc;
https://deepikamatam.blogspot.com/2019/07/aggregate-result.html