You need to sign in to do that
Don't have an account?
Uttirna 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
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
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
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
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;
}