• DVS
  • NEWBIE
  • 0 Points
  • Member since 2013

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

 

When my custom object (which is the child) is updated, I want to update the Case (parent) which is in the custom object's lookup field.  Here is what I have so far but it doesn't seem to be kicking off when I go in and update the custom object.

 

trigger updateRelatedCasesFromCR on Case_CR__c (after update){

Set <Id> Case_Ids = new Set<Id>();
for (Case_CR__c child: trigger.new) 
	Case_Ids.add(child.Case__c);
List<Case> Cases_To_Update = [select o.id, o.CR_Updated__c from Case o where o.id in :Case_Ids];
for(Case o: Cases_To_Update)
{ 
	o.CR_Updated__c = datetime.now();
}
update Cases_To_Update;
}

 

  • May 13, 2013
  • Like
  • 0

When a parent Case gets updated, how can I set up a trigger to update all the childcases? I don't need to update any of the fields on the child, just need the modified date to change.

 

Here is what I have so far but it is not working correctly.

 

trigger updateRelatedCasesfromParent on Case (after update) {
    
If(Trigger.isUpdate){
     
    Set<ID> ids = new Set<ID>();
     list<Case> updatedParents = [SELECT Id, reason FROM Case 
                 WHERE Id in :ids];
     List<Case> childrenToUpdate = new List<Case>();

         //Then loop through each parent object in 'updated parent
         for ( Case p : updatedParents) 
         { 
                //and loop thru each kid in the child set}
               for(Case kid : p.Cases) 
               { 
                    childrenToUpdate.add(kid);
                }
        }
       //if( !childrenToUpdate.isEmpty)
       //{
            update childrenToUpdate;
       //}
}
}

 Thanks for the help.

  • May 08, 2013
  • Like
  • 0

When a parent Case gets updated, how can I set up a trigger to update all the childcases? I don't need to update any of the fields on the child, just need the modified date to change.

 

Here is what I have so far but it is not working correctly.

 

trigger updateRelatedCasesfromParent on Case (after update) {
    
If(Trigger.isUpdate){
     
    Set<ID> ids = new Set<ID>();
     list<Case> updatedParents = [SELECT Id, reason FROM Case 
                 WHERE Id in :ids];
     List<Case> childrenToUpdate = new List<Case>();

         //Then loop through each parent object in 'updated parent
         for ( Case p : updatedParents) 
         { 
                //and loop thru each kid in the child set}
               for(Case kid : p.Cases) 
               { 
                    childrenToUpdate.add(kid);
                }
        }
       //if( !childrenToUpdate.isEmpty)
       //{
            update childrenToUpdate;
       //}
}
}

 Thanks for the help.

  • May 08, 2013
  • Like
  • 0