• Shawnh77
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

Hello, 

TIA for your assistance.

 

So the scenario is that I have a Parent case and many child cases.  However they are not in a Master relationship.  When the child cases are being created I have a trigger being fired that will update fields on the parent with a could of the total children.  Ultimately I will also have additional triggers that will also update additional fields based on a second field (Status__c) on the child. 

 

Currently even if I create one new child record I am getting an error with too many SOQL queries.  I am guessing based on what I've read in other posts that I have a query inside a loop.  However I cannot figure out how to get around this.  Any suggestions would be GREATLY appreciated.

 

Here's my trigger and class:

 

trigger CountMTMTrigger on AIO_Serials__c (after insert, after update) {

    AIO_Serials__c [] scl = Trigger.new;
   CountMTM.CountMTMS(scl);
   }

 

public class CountMTM {
public static void CountMTMS (AIO_Serials__c[] scl) {
for (AIO_Serials__c b :scl) {
   String sid=null;
   sid=scl[0].Case__c;
   Integer i = [select count() from AIO_Serials__c where Case__c = :sid];
   Case[] s=[select Count_of_Machines__c from Case where id=:sid];
   s[0].Count_of_Machines__c=i;
   system.debug('value is not there'+i);
   update s[0];
      }
   }
   }

 

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];

}

 

Hello, 

TIA for your assistance.

 

So the scenario is that I have a Parent case and many child cases.  However they are not in a Master relationship.  When the child cases are being created I have a trigger being fired that will update fields on the parent with a could of the total children.  Ultimately I will also have additional triggers that will also update additional fields based on a second field (Status__c) on the child. 

 

Currently even if I create one new child record I am getting an error with too many SOQL queries.  I am guessing based on what I've read in other posts that I have a query inside a loop.  However I cannot figure out how to get around this.  Any suggestions would be GREATLY appreciated.

 

Here's my trigger and class:

 

trigger CountMTMTrigger on AIO_Serials__c (after insert, after update) {

    AIO_Serials__c [] scl = Trigger.new;
   CountMTM.CountMTMS(scl);
   }

 

public class CountMTM {
public static void CountMTMS (AIO_Serials__c[] scl) {
for (AIO_Serials__c b :scl) {
   String sid=null;
   sid=scl[0].Case__c;
   Integer i = [select count() from AIO_Serials__c where Case__c = :sid];
   Case[] s=[select Count_of_Machines__c from Case where id=:sid];
   s[0].Count_of_Machines__c=i;
   system.debug('value is not there'+i);
   update s[0];
      }
   }
   }

 

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];

}