I have the task of counting how many Events per user, per month have a checkbox (Request Meeting Bonus) selected. How can this be done? That number will determine the amount Bonus_MR__c is per user. That part should be easily done with a process or workflow. My main problem is calulating the number of Requests.
You can check this code..Here I'm updated the user Total_Request_Meeting_Bonus__c fields based on number of events which has Request_Meeting_Bonus__c true Note- I have not compiled this code
trigger Counteventon event(after insert, after update) {
public List<ecent> ltask1 = new List<event>();
public id userids;
public integer inp=0;
public integer inr=0;
for(event t:Trigger.New){
userids = t.WhatId;
}
ltask1 = [select id,Requested_meeting_bonus__c from task where whatid=:oppid];
for(event t:ltask1){
if(t.Requested_meeting_bonus__c==true){
inp = inp+1;
} else{
inr = inr +1;
}
}
List<user> uopp = new List<user>();
List<user> userop = [select id from user where id = :userids];
for(user u: userop){
u.Total_Requested_meeting_bonus__c = inp;
uopp.add(u);
}
if(uopp.size()>0){
update uopp;
}
}
Error: Compile Error: Variable does not exist: oppid at line 12 column 76
ltask1 = [select id,Requested_meeting_bonus__c from task where whatid=:oppid];
Best,
Angie
@Angela, You can try something like this and update the line 12
Date startOfMonth = Date.today().toStartOfMonth(); Date startOfNextMonth = startOfMonth.addMonths(1);
ltask1 = [select id,Requested_meeting_bonus__c from event where ownerid=:userids where CreatedDate >= :startOfMonth AND CreatedDate < :startOfNextMonth];
Check this example http://developer.salesforce.com/forums/?id=9060G0000005OKkQAM (http://developer.salesforce.com/forums/?id=9060G0000005OKkQAM )
or let me know if you have a specific situation where you would like to count the record.
--
Thanks,
Prashant
Oops, that link doesn't exist.
Please use this link..somehow salesforce is adding an extra parameter in the url..
https://developer.salesforce.com/forums/?id=9060G0000005OKkQAM
--
Thanks,
Prashant
You can check this code..Here I'm updated the user Total_Request_Meeting_Bonus__c fields based on number of events which has Request_Meeting_Bonus__c true
Note- I have not compiled this code
--
Thanks,
Prashant
userids = t.ownerid;
ltask1 = [select id,Requested_meeting_bonus__c from event where ownerid=:userids];
--
Thanks,
Prashant
Hit like and mark this as the best answer.
--
Thanks,
Prashant
You can try something like this and update the line 12
Date startOfMonth = Date.today().toStartOfMonth();
Date startOfNextMonth = startOfMonth.addMonths(1);
ltask1 = [select id,Requested_meeting_bonus__c from event where ownerid=:userids where CreatedDate >= :startOfMonth AND CreatedDate < :startOfNextMonth];
--
Thanks,
Prashant
Please close this thrad by marking the best answer..
--
Thanks,
Prashant