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
SFineSFine 

Updating a child line item quantity and price

Hello everyone.

 

I'm currently trying to get a function to work that would either a) match the child quantity with that of it's parents or b) make the child price value be a percentage of it's parents.

 

We originally had the relationship from child to parent and in that regard it worked fine, but now they want it to be from parent to child and while I've gotten everything else to work fine. This particular function I can't get and I was hoping some light could be shed onto it.

 

I'll just show the main part I'm working with

 

 

for(OLIListWrapper oli:opp_products_list){
   if(oli.Item.Quantity<=0 || oli.Item.UnitPrice<0 || oli.Item.Quantity==null){
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.WARNING, 'Quantities must be greater than 0 and prices cannot be negative.');
    ApexPages.addMessage( myMsg);
    return null;
   }
   
   QuoteLineItem olnew=new QuoteLineItem();
   Decimal DiscountPrice;
   olnew.PricebookEntryId=oli.Item.PricebookEntryId;
   olnew.UnitPrice=oli.Item.UnitPrice;  
   olnew.QuoteId=opp.Id;     
   olnew.Notes__c=oli.Item.Notes__c;
   oli.quantity=oli.item.Quantity;   
   olnew.Description=oli.Item.Description;
   if(oli.over !=null)
                olnew.isOverage__c=oli.over;
   if(oli.hasRelate !=null)
                olnew.hasOverage__c=oli.hasRelate;
   olnew.Quantity=oli.Quantity;
   
   System.debug('Quantity Item - ' +oli.quantity);
   //if(!oli.over)
   if(oli.related!=null && oli.Dependency=='Set Child Qty from Parent')
   {
       boolean find=false;
       System.debug('*** Parent quantity is being selected *** Product List: '+opp_products_list);
       
       for(OLIListWrapper i:opp_products_list)
       {
           System.debug('RELATED PARENT - ' +oli.related);
           System.debug('RELATED Child - ' +i.identity);
   
           if(oli.related == i.identity)
           {
                oli.Quantity=i.quantity;
                find=true;
                System.debug('New Child Quantity - '+i.quantity);
           }
       }
   }
   else
   {
        olnew.Quantity=oli.Quantity;
   }
   
   if(oli.related!=null && oli.Dependency=='Set Child Price as % of Parent Price')
   {
       boolean find=false;
       System.debug('*** Parent quantity is being selected ***');
       
       for(OLIListWrapper i:opp_products_list)
       {
           if(oli.related == i.Identity && i.item.MRC_RATE__C!=null)
           {
                i.item.MRC_Rate__c=oli.item.MRC_RATE__C * (oli.ChildPercent/100); //10% test for MRC rate
                find=true;
           }
       }
       if(!find)
       {
          ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.ERROR, 'There is a problem here. Please try saving again. If the problem persists, please contact your administrator...?');
          ApexPages.addMessage( myMsg); 
          olnew.MRC_Rate__c=100; 
       }
   }
}

 

 

The variable identity is the product id while the variable 'related' is the id of the child relation the product has.

 

The idea I had was that when loop through to find the child, it would change the custom LineItemWrapper value of quantity and then when the child goes through, it'll pick up the new quantity, but it never seems to do that. ANy ideas why or solutions?

 

Also, I'm not entirely sure if the price section would work. Could anyone give some clarification or ideas?