2 réponses
Hi,Thank you, but I cannot get this to work for me, in my code. My understanding was these two pieces of code should pass the parent ID to the child record: SessionId=ApexPages.currentPage().getParameters().get('class_enrollments.SessionId');And then: Pagereference page=new pagereference('/'+SessionId);However, I continue to get this error:System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Session]: [Session]Error is in expression '{!insertClass_Enrollments}' in component <apex:commandButton> in page add_class_enrollments: Class.AddingEnrollmentsController.insertClass_Enrollments: line 14, column 1Class.AddingEnrollmentsController.insertClass_Enrollments: line 14, column 1So, something is wrong with this section of code: public AddingEnrollmentsController(ApexPages.StandardSetController controller){ SessionId=ApexPages.currentPage().getParameters().get('class_enrollmentsList.SessionId'); class_enrollmentsList = new List<Class_Enrollments__c>(); class_enrollmentsList.add(new Class_Enrollments__c()); } public pagereference insertClass_Enrollments(){ insert class_enrollmentsList ; Pagereference page=new pagereference('/'+SessionId); Return page;} Any thoughts? Additionally, I have been trying all morning to assign all newly created child records the appropriate record type ID. I want them all to have the same record type, so I just need to assign that on record creation. I have tried to add various types of code, including "Id recordTypeId = Schema.SObjectType.OBJECT_NAME.getRecordTypeInfosByDeveloperName() .get('RECORD_TYPE_DEVELOPER_NAME').getRecordTypeId();" and simply, "class_enrollmentsList.RecordTypeId = recordTypeId (with the actual record type ID);but that is throwing me an error too.I updated my VF page so that i am using the standard controller for the parent object, instead. I think one error was using the Child object. My list button directs to this URL: /apex/Add_Class_Enrollments?SessionId={!Class_Enrollments__c.SessionId__c}I feel like I'm soooo close. Any help?