You need to sign in to do that
Don't have an account?
Kiran Kumar 225
Trigger for update child status value
hi, I have a following code, which updates all child records when status changes from complete to not complete. but my code is not woking.
trigger status on Product__c (after update) {
set<String> productId = new set<String>();
for(Product__c pro : trigger.old){
if(pro.Status__c == 'Complete'){
productId.add(pro.id);
System.debug('Completed--->'+pro);
}
}
List<Vehicle__c> vechicalList = new List<Vehicle__c>();
for(Vehicle__c vech:[select id,name,Status__c,Product__r.Status__c from Vehicle__c WHERE Product__c IN: productId ]){
system.debug('vech---->'+vech);
if(vech.Product__r.Status__c== 'Not Completed'){
vech.Status__c = 'Incomplete';
vechicalList.add(vech);
}
}
update vechicalList;
}
Kindlyletme know where I did mistake.
trigger status on Product__c (after update) {
set<String> productId = new set<String>();
for(Product__c pro : trigger.old){
if(pro.Status__c == 'Complete'){
productId.add(pro.id);
System.debug('Completed--->'+pro);
}
}
List<Vehicle__c> vechicalList = new List<Vehicle__c>();
for(Vehicle__c vech:[select id,name,Status__c,Product__r.Status__c from Vehicle__c WHERE Product__c IN: productId ]){
system.debug('vech---->'+vech);
if(vech.Product__r.Status__c== 'Not Completed'){
vech.Status__c = 'Incomplete';
vechicalList.add(vech);
}
}
update vechicalList;
}
Kindlyletme know where I did mistake.
You can do this like below, first you need to check the status is changed or not and then check its 'Complete'
Let me know in case it doesn't work.
Thanks.
All Answers
Use the below code it will work,
FYI, You can acheive this using process builder to update all child record status when the status is Completed.
Let me know if you need any help regarding this.
Thanks,
Vijay
You can do this like below, first you need to check the status is changed or not and then check its 'Complete'
Let me know in case it doesn't work.
Thanks.