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
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
 
EldonEldon
Hi,

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.

Regards
Mukesh_SfdcDevMukesh_SfdcDev
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.

Thanks
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) 
        {
            setAccountId.add(PM.Quote_Name__c);
        }
        for(Quote__c a : [Select Id,(Select Id,Product__c from Quotation_Line_Items__r) from Quote__c where id =: setAccountId])
        {
            mapAccountIdCount.put(a.Id,a.Quotation_Line_Items__r.size()); 
        }
        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;
                
                PBI.Kick_Off_Date__c=PM.Kick_Off_Date__c;
                PBI.Name=PM.Account_Name__c;
                PItem.add(PBI);
            }
        }
        insert PItem;
    }