You need to sign in to do that
Don't have an account?
Jean Grey 10
Map of User Ids and Total Sales this Month
I have a trigger on Opp, after each insert/update I need to recalculate a user's sales for the month. I have the user set and I can do an aggregate query, but how do I connect these in the map?
Here is what I have so far, any help would be appreciated!
Here is what I have so far, any help would be appreciated!
//get total current count of opps oppList = [SELECT Id,Amount FROM Opportunity WHERE CloseDate = THIS_MONTH AND StageName = 'Closed–Won']; //add opps to set to get comm splits for(Opportunity o:oppList){ oppSet.add(o.Id); } //get aggregate of all commission splits csAgg = [SELECT SUM(Split_Amount__c),User__c FROM Commission_Split__c WHERE Opportunity__c IN :oppSet]; //get comm splits attached to this opp csList = [SELECT Id,Split_Amount__c,User__c,Opportunity__c FROM Commission_Split__c WHERE Opportunity__c IN :oppSet]; //get users for(Commission_Split__c c:csList){ userSet.add(c.User__r.Id); } //now I have my users in a Set, and aggregate results above, how do I connect? public Map<Id, AggregateResult> userSales = new Map<Id,AggregateResult>([SELECT SUM(Split_Amount__c) FROM Commission_Split__c WHERE User__c IN :userSet)]);
Your code will look something like this: Please note that code might vary depending upon your map structure.
Let me know if it helps.
Thanks!
All Answers
Plase check once below sample code:
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Use this code snippet:
Let me know if it helps.
Regards,
Nads
Your code will look something like this: Please note that code might vary depending upon your map structure.
Let me know if it helps.
Thanks!