I'm attempting to summarize invoice data by type of invoice grouped by time period. Income_Class__c is a picklist field and upon running this code I get an error: Invalid conversion from runtime type integer to string.
1 - What do I need to modify here to get the correct Income_Class__c picklist value to display?
2 - When this runs I get more results than desired. Any idea how I can make this only create records grouped by Income Class and Month (but also display the calendar year?).
AggregateResult[] RevDataMonth = [SELECT GROUPING(Income_Class__c) IncomeGroup, CALENDAR_MONTH(Transaction_Date__c) CalMonth,
CALENDAR_YEAR(Transaction_Date__c) CalYear, SUM(Net_Revenue__c) SumRev
FROM Invoice__c
WHERE Company__c = '001Q000000VDkpq'
GROUP BY ROLLUP(Income_Class__c, CALENDAR_MONTH(Transaction_Date__c), CALENDAR_YEAR(Transaction_Date__c))];
{
for (AggregateResult a : RevDataMonth){
RevRollupAug12__c r = new RevRollupAug12__c();
r.month__c = (Integer)a.get('CalMonth');
r.year__c = (Integer)a.get('CalYear');
r.Amount__c = (Decimal)a.get('SumRev');
r.company__c = '001Q000000VDkpq';
r.Time_Period__c = 'Month';
r.Income_Class__c = (String)a.getvalue('IncomeGroup');
insert r; }}}