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

Problem with typecasting from a aggregated query, Plese help me
trigger Behr_AmountOfMonths_US on THD_Sales__c (after insert,after update) { Set<Id> accset = new Set<Id>(); Set<Id> thdset = new Set<Id>(); List<THD_Sales__c> thdlst = new List<THD_Sales__c>(); Map<Id,THD_Sales__c> thdmap = new Map<Id,THD_Sales__c>(); map<Id,Double> AccountMap = new map <Id,Double>(); for(THD_Sales__c thd : Trigger.new) { if(thd.POS_Order_Type__c == 'Special Order') { accset.add(thd.SFDC_Account_ID__c); } } for(AggregateResult q:[SELECT SFDC_Account_ID__c,sum(Amount__c)tot FROM THD_Sales__c where SFDC_Account_ID__c in :accset group by SFDC_Account_ID__c]) { AccountMap.put((Id)q.get('SFDC_Account_ID__c'),(Double)q.get('expr0')); } }
Error: Compile Error: line 15:69 no viable alternative at character '' at line 15 column 69
AccountMap.put((Id)q.get('SFDC_Account_ID__c'),(Double)q.get('expr0'));
try this and let me know:
for(AggregateResult q:[SELECT SFDC_Account_ID__c sfdcAccId,sum(Amount__c)tot FROM THD_Sales__c where SFDC_Account_ID__c in :accset group by SFDC_Account_ID__c])
{
Id sfdcId = (Id) q.get('sfdcAccId');
Double dTotal = (decimal) q.get('tot');
AccountMap.put(sfdcId, dTotal);
}
All Answers
try this and let me know:
for(AggregateResult q:[SELECT SFDC_Account_ID__c sfdcAccId,sum(Amount__c)tot FROM THD_Sales__c where SFDC_Account_ID__c in :accset group by SFDC_Account_ID__c])
{
Id sfdcId = (Id) q.get('sfdcAccId');
Double dTotal = (decimal) q.get('tot');
AccountMap.put(sfdcId, dTotal);
}
Thank you Laxman.