+ Start a Discussion
Uttirna DasUttirna Das 

Trigger for creating multiple records on a child object on creation of parent object against another parent object's child objects

I have Quote object which has Child object Quotation Line Item and I have PO object which has child object named Project .

PO has Lookup with Quote, So when I will create a new PO from Quote, Same number of Projects should create under PO against each Quotation Line Item,

I tried the following code but it is not capturing Quotation Line Item Name against which one which project created. Please Help me to Resolve this
User-added image

Always try to type your code in here so that its easier for others to debug and reply.

In the code you have project_management__c , subproject__c project please clarify on these objects.

Hello Uttima,

Your code is looking fine Could you please provide the code snippet through the code editor.
Also please tell in which line you are stuck.

Mukesh Kumar
Uttirna DasUttirna Das
My code is working but I want Quotation Line Item Number also into Project to know from which Quotation Line Item's respective which Project has been created but I am not getting that.Please Help me 
That following is my code, 
Project_Management__c = PO
SubProject__c= Project

trigger CreateProjecttLineItems on Project_Management__c (after insert) {
        List<SubProject__c> PItem = new List<SubProject__c>();
        Set<Id> setAccountId = new Set<Id>(); 
        Map<Id,Integer> mapAccountIdCount = new Map<Id,Integer>(); 
        for (Project_Management__c PM : trigger.new) 
        for(Quote__c a : [Select Id,(Select Id,Product__c from Quotation_Line_Items__r) from Quote__c where id =: setAccountId])
        for (Project_Management__c  PM: trigger.new) 
            for(Integer i=0; i<mapAccountIdCount.get(PM.Quote_Name__c);i++)
                SubProject__c PBI = new SubProject__c();
                PBI.Project_Name__c= PM.id;
        insert PItem;