Skip to main content
2 respostas
  1. 4 de jun. de 2021, 06:55
    Hi Venkatesh,

    "This is sample code in this Library__c is parent of Book__c

     In this when I created library__c record then Book__c record

     also created and IssueDate__c is field of Library__c Object,it

     will populate to BookDate__c which is field of Book__c."

    //Trigger

    trigger LibraryTrigger on Library__c (after insert) {

        if(trigger.isAfter){

            if(trigger.isInsert){

                Library_Book_Class.createBook1(Trigger.new);

            }

        }

    }

    //Apex Class

    public class Library_Book_Class {

        public static void createBook1(List<Library__c> Lib_List)

        {

            System.debug('list--->: '+Lib_List);

            List<Book__c> bookList=new List<Book__c>();

            for(Library__c lib1:Lib_List)

            {

                Book__c book1=new Book__c();

                book1.Library_Look__c=lib1.id;

                book1.Name='Book1';

                book1.BookDate__c=lib1.IssueDate__c;

                bookList.add(book1);

                System.debug('list- in loop-->: '+bookList);

                

            }

        if(!bookList.isEmpty())

        {

            insert bookList;

            

            System.debug('list- out loop-->: '+bookList);

            

        }

    }

    }

    If you find your Solution then mark this as the best answer. 

    Thank you!

    Regards 

    Suraj Tripathi