You need to sign in to do that
Don't have an account?
manikanta sinisetti
Getting error when , I wrote a trigger --which should undelete child records when parent record is undeleted
Hi all,
This is my code:
//If Parent record is undeleted , it's child records should also be undeleted.
trigger Trg9 on Student__c (after undelete) {
List<id> StdId=new List<id>();
for(Student__c s: trigger.new){
StdId.add(s.id);
}
list<StudentChild__c> childRecords=[select id,College_of_Student__c,Name from StudentChild__c where College_of_Student__c in :StdId all rows];
undelete childRecords;
}
I am getting Error when Undeleing parent record:
Please can any one help me out , how to resolve this.
Thanks In Advance.
This is my code:
//If Parent record is undeleted , it's child records should also be undeleted.
trigger Trg9 on Student__c (after undelete) {
List<id> StdId=new List<id>();
for(Student__c s: trigger.new){
StdId.add(s.id);
}
list<StudentChild__c> childRecords=[select id,College_of_Student__c,Name from StudentChild__c where College_of_Student__c in :StdId all rows];
undelete childRecords;
}
I am getting Error when Undeleing parent record:
Please can any one help me out , how to resolve this.
Thanks In Advance.
can you tell me What relation is between Student__c and StudentChild__c ?
Lookup Relationship or Master-Detail Relationship ?
If Relationship is 【Master-Detail Relationship】,
yes, your error will happens. I got same error with you. if Relationship is 【Master-Detail Relationship】
you need not run trigger to undelete the child record, because it will undelete automaticaly.
If Relationship is 【Lookup Relationship】,
Yes, Child record can be undeleted when Undeleing parent record:
I have two objects below, similar to you.
employee__c ---> parent object
employeeTask__c ---> child object
------------------------------------------------------------------------------------
trigger Trg9 on employee__c (after undelete) {
list<employeeTask__c> childRecords=[select id,employee__c,Name from employeeTask__c where employee__c in :trigger.new all rows];
system.debug('childRecords------------->'+ childRecords);
system.debug('trigger.new------------->'+ trigger.new);
undelete childRecords;
}
------------------------------------------------------------------------------------
I hope it will help you.
All Answers
Update the SOQL to include isdeleted = true
Please mark as best answer if the above helps ..!!!
can you tell me What relation is between Student__c and StudentChild__c ?
Lookup Relationship or Master-Detail Relationship ?
If Relationship is 【Master-Detail Relationship】,
yes, your error will happens. I got same error with you. if Relationship is 【Master-Detail Relationship】
you need not run trigger to undelete the child record, because it will undelete automaticaly.
If Relationship is 【Lookup Relationship】,
Yes, Child record can be undeleted when Undeleing parent record:
I have two objects below, similar to you.
employee__c ---> parent object
employeeTask__c ---> child object
------------------------------------------------------------------------------------
trigger Trg9 on employee__c (after undelete) {
list<employeeTask__c> childRecords=[select id,employee__c,Name from employeeTask__c where employee__c in :trigger.new all rows];
system.debug('childRecords------------->'+ childRecords);
system.debug('trigger.new------------->'+ trigger.new);
undelete childRecords;
}
------------------------------------------------------------------------------------
I hope it will help you.