You need to sign in to do that
Don't have an account?
Shawnh77
Newbie question for a custom count
Hello,
I am trying to count the number of child records based on a custom object of "Status_c". My Parent is "Case" and the child records are "AIO". On the AIO record there is the Status and a few other fields. What I am trying to do is count the children based on the status. Once I have that count I am writing it back to another custom object in the parent "Count_of_M". I've been looking through other posts and have been unsuccessful in adapting the examples posted to do what I need. Thank you in advance for any suggestions!!
Shawn.
trigger CountRelatedCallLogs_fromLog on AIO__c (after insert, after update) { AIO__c [] scl = Trigger.new; String sid = null; // progress = "In Progress"; sid = scl[0].Related_Case__c; Integer i = [select count() from AIO__c where Status_c = :sid]; // update the master record Case_ID__c [] s =[select id, Count_of_Pending__c from Case_ID__c where id = :sid]; s[0].Call_Count__c = i; // write to database update s[0]; }
Is this a master detail relationship? If so, seems a roll up summary would work well.
Hope it helps
Sam,
Thank you for the feedback. I clearly do not understand the code. What I am trying to do is count the number of child objects that meet a certain status. I have a custom object called "Status__c" Becuase they are seperate records I do not have the child (related case) as an option in a roll up summary. I tried using the code you supplied but get an error on compile that the object is not supported on Line12.
Thank you for your help.
Unfortunately no. They are related objects in a Parent/Child relationship.
When you say/ parent/child, you mean a Lookup relationship?
Yes, They are two separate records. One is the standard CASE and the other is a different layout of CASE where I am adding the first case number to the layout. I have a field on the first CASE that will serve to hold the quantity of the second record type where a certain status (a custom object picklist) meets the criteria. There are four total fields on the first record: Total count, total pending, total complete, total new.
I really appreciate your assistance.
Shawn
Ok, so I think this should do what I need.However I am getting the folowing error. "Error: Compile Error: Invalid type: Case__c at line 10 column 5". Any Ideas? I was thinking that I needed to use Case__c to reference back to the main record. AIO_Serials__c is my second record.