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
sfdeveloper12sfdeveloper12 

Update field on Quote line item

Hello,

I have to update field on Quote line item(PSL Rate).
I am updating this value from "Agreed Rate" field on "Rate & commision" object. "Rate and Commision" object is child object of Product.
On quote line item when i will add the product. My trigger will check for Account field on Quote object and account(lookup) field on Rate and commisio object.
If this both account is same then i will update field on rate and commison object on qoute line item object.
Rate and commision object have multiple records. So i have to choose record having same name in quote object.

I have written a code. Its giving me product id. As in both 'quote line item' and 'Rate and commsion' object Product object is common.

I dont know how to take Rate and commision now in trigger with same product id

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>();

        for (QuoteLineItem childObj : Trigger.new) {
            if(QuoteID == null) {
               QuoteID  = childObj.QuoteID;
            }
            if(childObj.Product2Id != null){
                PIds.add(childObj.Product2Id);
            }
        }
        system.debug('QuoteID 16 -->'+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 -->'+QuoteDetails );
                   
                    for (QuoteLineItem item : Trigger.new) {
     
                     // item.PSL_Rate__c = 5500;
                      //List<Rates_Commissions__c> rate = [select Id, Client_Account__c,Venue_Hotel__c from Rates_Commissions__c where Product_Item__c =:item.Product2Id]; 

                      system.debug('item -->'+item );
                      //system.debug('rate -->'+rate );


             //  update item;
                   
               }   
                   for(Product2 product :[select id, name   from Product2 where Id IN : PIds]){
                                             system.debug('product -->'+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 -->'+rate ); 
            
        }   
                   }
                   
        }
                           
            }
                 // 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
    }
}