You need to sign in to do that
Don't have an account?
sfdeveloper12
How to take list of child object into parent object?
Hello,
I am writing code where i am stuck as i am not getting list of child object(Rate and Commision) in partent object(Product).
I have checked using debug statement. My code is giving me list of products selected in quote line item. But not the list of record and commsion objects record in product.
trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
system.debug('****************InTrigger**********************');
if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
String QuoteID ;
set<id> PIds = new set<id>();
// set<id> RCIds = new set<id>();
for (QuoteLineItem childObj : Trigger.new) {
if(QuoteID == null) {
QuoteID = childObj.QuoteID;
}
if(childObj.Product2Id != null){
PIds.add(childObj.Product2Id);
}
}
system.debug('QuoteID 19 -->'+QuoteID );
if(QuoteID != null) {
List<Quote> quotes = [select Id, AccountId, Venue__c from Quote where Id =:QuoteID ];
if(quotes.size() > 0) {
Quote QuoteDetails = quotes[0];
system.debug('QuoteDetails 26 -->'+QuoteDetails );
for (QuoteLineItem item : Trigger.new) {
system.debug('item 29 -->'+item );
}
for(Product2 product :[select id, name, (select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__r) from Product2 where Id IN : PIds]){
system.debug('product 34 -->'+product );
List<Rates_Commissions__c> rate = [select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ];
// for(Rates_Commissions__c rate :[select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ])
system.debug('rate 39 -->'+rate );
}
}
}
/* if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
{
rate.Agreed_Rate__c = item.PSL_Rate__C;
}
*/
// select Id,agrredrate from rate ommison where productrc=pid && ratecommison.clinetacc=quoteacc && ratecommisonvenue = qotevenue ====== Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id
}
}
This is my code. Sometimes i get error that loop variable must be of quote line item. Can anyone help to get list of child records?
Thanks & Regards,
Utkarsha
I am writing code where i am stuck as i am not getting list of child object(Rate and Commision) in partent object(Product).
I have checked using debug statement. My code is giving me list of products selected in quote line item. But not the list of record and commsion objects record in product.
trigger UpdateAgreedRate on QuoteLineItem (before insert, before update) {
system.debug('****************InTrigger**********************');
if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
String QuoteID ;
set<id> PIds = new set<id>();
// set<id> RCIds = new set<id>();
for (QuoteLineItem childObj : Trigger.new) {
if(QuoteID == null) {
QuoteID = childObj.QuoteID;
}
if(childObj.Product2Id != null){
PIds.add(childObj.Product2Id);
}
}
system.debug('QuoteID 19 -->'+QuoteID );
if(QuoteID != null) {
List<Quote> quotes = [select Id, AccountId, Venue__c from Quote where Id =:QuoteID ];
if(quotes.size() > 0) {
Quote QuoteDetails = quotes[0];
system.debug('QuoteDetails 26 -->'+QuoteDetails );
for (QuoteLineItem item : Trigger.new) {
system.debug('item 29 -->'+item );
}
for(Product2 product :[select id, name, (select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__r) from Product2 where Id IN : PIds]){
system.debug('product 34 -->'+product );
List<Rates_Commissions__c> rate = [select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c, Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ];
// for(Rates_Commissions__c rate :[select Id, Agreed_Rate__c, Product_Item__c, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:product.Name ])
system.debug('rate 39 -->'+rate );
}
}
}
/* if(quotes.AccountId == rate.Client_Account__c && quotes.Venue__c == rate.Venue_Hotel__c)
{
rate.Agreed_Rate__c = item.PSL_Rate__C;
}
*/
// select Id,agrredrate from rate ommison where productrc=pid && ratecommison.clinetacc=quoteacc && ratecommisonvenue = qotevenue ====== Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id
}
}
This is my code. Sometimes i get error that loop variable must be of quote line item. Can anyone help to get list of child records?
Thanks & Regards,
Utkarsha
Raj Vakati
Your Query is wrong Seems to be . This trigger does not work for bulk data