You need to sign in to do that
Don't have an account?
DVS
Trying to update parent from Child. What am I doing wrong?
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; }
Hi just add this blue colored text in your code
trigger updateRelatedCasesFromCR on Case_CR__c (after update){
Set <Id> Case_Ids = new Set<Id>();
List<Case> updateCaseList = new List<Case>();
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();
updateCaseList.add(o);
}
if(updateCaseList.size()>0){
update updateCaseList;
}
}
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks
All Answers
do this
Case_Ids.add(child.id); line no 5
update Cases_To_Update;
Hi just add this blue colored text in your code
trigger updateRelatedCasesFromCR on Case_CR__c (after update){
Set <Id> Case_Ids = new Set<Id>();
List<Case> updateCaseList = new List<Case>();
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();
updateCaseList.add(o);
}
if(updateCaseList.size()>0){
update updateCaseList;
}
}
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks