function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

On creating a record in one object(Teacher) automatically a record should be created on the other object(Student).

Create two Objects say Teacher(Parent) and Student(Child) having similar fields. On creating record of Teacher, associated student record should be created and vice versa. Additionally, updates should also be in sync i.e. updating the parent should reflect in the child and vice versa.
I want to do this with the help of salesforce flow how to do that?

Prateek Prasoon 25Prateek Prasoon 25
Answer :-
To create a record in one object (Teacher) and automatically create a record in the other object (Student) in Salesforce using Apex, you can follow these steps:
Create two custom objects, Teacher and Student, with similar fields.
Create a lookup relationship field on the Student object to the Teacher object.
Create a trigger on the Teacher object that creates a new Student record when a new Teacher record is created.
In the trigger, create a new Student record and set the field values from the new Teacher record. Make sure to set the lookup field to link the Student record to the Teacher record.
Insert the new Student record into the database.
Here's some sample code to get you started:
trigger UpdateStudentRecord on Teacher__c (after update) {
    List<Student__c> updatedStudents = new List<Student__c>();
    for (Teacher__c teacher : {
        List<Student__c> relatedStudents = [SELECT Id, Name, Age__c, Gender__c FROM Student__c WHERE Teacher__c = :teacher.Id];
        for (Student__c student : relatedStudents) {
            student.Name = teacher.Name; // update field values from Teacher record
            student.Age__c = teacher.Age__c;
            student.Gender__c = teacher.Gender__c;
    update updatedStudents; // update related Student records in database

If you find my answer helpful, please mark it as the best answer. Thanks!
Nithyanandha NimmalaNithyanandha Nimmala
you can achieve this using record triggerd flow.