You need to sign in to do that
Don't have an account?
Kanika Dua 1
Counting Total Number of Cases
Hi All,
I am newbiee to Salesforce.I have two Objects Case and a custom Object CaseReplica.On Case Replica I have a custom Field Total Cases.What I want to do is count Total number of cases created in a day and save that number in field Total Cases in CaseReplica.One Record For a day should be created in CaseReplica.Please suggest me methods to do it.
Thanks in advance
I am newbiee to Salesforce.I have two Objects Case and a custom Object CaseReplica.On Case Replica I have a custom Field Total Cases.What I want to do is count Total number of cases created in a day and save that number in field Total Cases in CaseReplica.One Record For a day should be created in CaseReplica.Please suggest me methods to do it.
Thanks in advance
you can check this sample trigger for updating realtime count of cases in CaseReplica__c .This trigger handels both insert and delete of case record.
if you insert a new case then TotalCase__c in CaseReplica__c will updated with new count and if you delete a case then count will decrese also.
please do let me know if it helps you
Thanks,
Debasis
All Answers
the easiest way to count related records is to make a Master-Detail connection between them and then use the aggregate Formula field to count related detail records on your master object. You do that by adding a new custom field of type Master-Detail Relationship.
To create a new record every day, use a scheduled job.
I want to count Cases.And We Can not make Case as a detail in Master Detail Relationship
@Kanika,
Then make a trigger that on every Case insert adds 1 to the Total Cases field in CaseReplica.
Or create a scheduled job that runs at the end of the day and goes over all Cases created that day and saves their count to the Total Cases field in CaseReplica. Something like this:
SELECT Count() FROM Case WHERE DateCreated = Date.Today()
I prefer the second option.
Use a scheduler apex for this and schedule it for everyday night after 12am. I have written below sample scheduled class for this. please scheduled this class to run everyday at 1am as per below image.
please do let me know if it helps you.
Thanks,
Debasis
Thanks For Responding.But Solution of Scheduled Job Seems to be Static as it will Execute at 1 AM.I want to see real Time data.ie. For every new Case record of CaseReplica is Updated.How I can accomplish that.Can you please Help me with syntax for Trigger and On which object Trigger should be Created on Case or CaseReplica?
Thanks in advance
you can check this sample trigger for updating realtime count of cases in CaseReplica__c .This trigger handels both insert and delete of case record.
if you insert a new case then TotalCase__c in CaseReplica__c will updated with new count and if you delete a case then count will decrese also.
please do let me know if it helps you
Thanks,
Debasis
please let me know if you need any further assistance or any of above answer hemos you to resolve your issue.
Thanks,
Debasis