You need to sign in to do that
Don't have an account?

create bulk child records when parent record is created
I have Parent and Child two objects with lookup relation.
in parent obje we have Location text field.
in child obj also we have Location text field.
whenever createding paren record with Boston as Location .. it need to check in child object . if in child obj with Location Boston if we found 6 records then need to cratee 6 child records.
please help me on this.
trigger CreateChild on Parent__c (after insert) {
List<Child__c> Childs = new List<Child__c>();
for(Parent__c a : trigger.new){
Child__c Child = new Child__c ();
Child.Parent__c = a.id;
Child.Name = 'testName';
Childs.add(Child);
}
insert Childs;
}
in parent obje we have Location text field.
in child obj also we have Location text field.
whenever createding paren record with Boston as Location .. it need to check in child object . if in child obj with Location Boston if we found 6 records then need to cratee 6 child records.
please help me on this.
trigger CreateChild on Parent__c (after insert) {
List<Child__c> Childs = new List<Child__c>();
for(Parent__c a : trigger.new){
Child__c Child = new Child__c ();
Child.Parent__c = a.id;
Child.Name = 'testName';
Childs.add(Child);
}
insert Childs;
}
Try with below code ,
Let me know if it helps !!
Thanks
Mnaoj
when i trying to say Location is Boston it not fixted.. it may be newyork or some other. when we are createding parent record with with Boston as Location it need to check in child object location object. if it found same x (8) records location value (boston). need to create new 8 child records with Location boston.
Still your requirment is not clear .Do you have any location object ? Please explain you rrequirment clearly so that I wil help you to solve .
Please expalin your requirments step by step .
in parent obje we have Location text field.
in child obj also we have Location text field.
location is text field user need to enter
whenever createding paren record with 'x' as Location .. it need to check in child any records avalable withobject Location=x.
if(parent.location=child.location){
need to get child record list size. for example size is 8
and need to crtae 8 new child records with location as X.
}
please let me know if need more clarity
One more thing while creating parent record ,or while creating child record as while creating parent record you may not have child record as once you will create parent record then only you can create child record below that.
Please clarify ..
Yes we cant see child info while createing parent. but we need to get data from child object and we need to compare.
This is like standard objs Account and contact. when creating Account record with location as 'X' . need to check all record of contact in sfdc then we need to check Contact records with Location as 'X' . if found some 8 records then need to create new 8 contact records with same data.