You need to sign in to do that
Don't have an account?
dssa
Dynamic Case Count
Hello all. I'm very new to Salesforce environment. Any suggestions would be much appreciated.
My org has 2 users who handle cases. User A & User B
I'm trying to code a trigger to get a dynamic count of cases closed by each user.
So far, this is what I have:
trigger t on Case (after insert, after update) for(case c: Trigger.New) integer i = [Select count() from Case where id =: trigger.new and isClosed = true and CreatedbyId=UserA]; integer j = [Select count() from Case where id =: trigger.new and isClosed = true and CreatedbyId=UserB]; update c;
Thanks in advance.
Cheers
Hi,
Try the below code snippet as reference:
trigger t on Case (after insert, after update)
{
user us = [select id,name from user where name ='UserA'];
user uss = [select id,name from user where name ='UserB'];
map<id,case> temp = trigger.oldmap;
set<id> tempset = new set<id>();
for(case cc:trigger.new)
{
tempset.add(temp.get(cc.id).id);
}
if(trigger.isinsert)
{
for(case c: Trigger.New)
{
integer i = [Select count() from Case where id in: tempset and isClosed = true and CreatedbyId=:us.id];
integer j = [Select count() from Case where id in: tempset and isClosed = true and CreatedbyId=:uss.id];
// now here you can count total closed case by userA and userB ny adding i plus j
//update c;
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi,
Do you want to keep this informaton how many cases are closed by a user ( in case record ). Idealy you should have a separed object Like
UserCases , whch will have Fields like NoOfAssigned Cases, Closed Cases . Each user wll have one such records having all the detals in it.
Let me know if you want me to set up this data model and comnfigurations.
Hello. Appreciate your prompt response.
Your solution makes perfect sense.
However, there is no pre-defined assignment of cases to each user (I'm not using the queue feature)
Do you still think it would work?
I followed your suuggestion. This is what I did
When I close the case as UserA, RSF is not updating the number.
Your thoughts?