Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
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

 
3 answers
  1. Dec 10, 2017, 4:31 AM
    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;

        }

     
Loading
0/9000