You need to sign in to do that
Don't have an account?
Apex Trigger - Illegal assignment from List to Decimal
Hello friends,
This is my second attempt at writing an apex trigger. I receiving an error when I save my trigger, "Illegal assignment from List to Decimal."
Hopefully someone can give me some pointers.
Here's my code:
trigger SRTake1 on Stack_Rank__c (after update) {
Date myDate = Date.newInstance(2017, 01, 01);
for( Stack_Rank__c s: Trigger.new){
if(s.SR_Date__c == myDate && s.SR_Main_Sales__c == null){
try{
s.SR_Main_Sales__c=[Select OwnerID, SUM(quota_credit__c) from Opportunity Where OwnerID in (Select User__c From Stack_Rank__c Where SR_Date__c = 2017-01-01) AND CloseDate >= 2017-01-01 AND CloseDate <= 2017-01-31 Group By OwnerId];
}
catch(QueryException ex) {
//todo add other entitlements
}
}
}
}
trigger SRTake1 on Stack_Rank__c (after update) {
Date myDate = Date.newInstance(2017, 01, 01);
for( Stack_Rank__c s: Trigger.new){
if(s.SR_Date__c == myDate && s.SR_Main_Sales__c == null){
try{
s.SR_Main_Sales__c=[Select SUM(quota_credit__c) from Opportunity Where OwnerID in (Select User__c From Stack_Rank__c Where SR_Date__c = 2017-01-01) AND CloseDate >= 2017-01-01 AND CloseDate <= 2017-01-31 AND StageName ='Closed Won'];
}
catch(QueryException ex) {
//todo add other entitlements
}
}
}
}
Even though you are using aggregate function it's still returning a list.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_agg_fns.htm
In your case creating a list, then getting [0] element and assigning it to s.SR_Main_Sales__c should do the trick.