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
Vasu@blrVasu@blr 

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'));

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

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

Laxman RaoLaxman Rao

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);
}

This was selected as the best answer
Vasu@blrVasu@blr

Thank you Laxman.