You need to sign in to do that
Don't have an account?
Priyesh Misquith 12
combining the similar line item from the list of values.
I have the list of line item from Opportuntiy
List<products__c> allProducts = [select id, name, quantity__c, price__c ,totalPrice__c from products where id:= parentOppIdid];
In the above list i am having multiple product with same name and
i want to combine the similar product as one ie combinig the similar product and adding the quantity__c ,totalPrice__c for productlineitem.
suppose list has
name=apple, quantity__c=2 , price__c= 20 , totalPrice__c = 40
name = watermelon , quantity__c=1 , price__c = 10 , totalPrice__c = 10
name = apple , quantity__c=3 , price__c = 20 , totalPrice__c = 60
I need a single list like
name = apple , quantity__c = 5 , price__c = 20 ,totalPrice__c = 100
name = watermelon , quantity__c=1 , price__c = 10 , totalPrice__c = 10
List<products__c> allProducts = [select id, name, quantity__c, price__c ,totalPrice__c from products where id:= parentOppIdid];
In the above list i am having multiple product with same name and
i want to combine the similar product as one ie combinig the similar product and adding the quantity__c ,totalPrice__c for productlineitem.
suppose list has
name=apple, quantity__c=2 , price__c= 20 , totalPrice__c = 40
name = watermelon , quantity__c=1 , price__c = 10 , totalPrice__c = 10
name = apple , quantity__c=3 , price__c = 20 , totalPrice__c = 60
I need a single list like
name = apple , quantity__c = 5 , price__c = 20 ,totalPrice__c = 100
name = watermelon , quantity__c=1 , price__c = 10 , totalPrice__c = 10
Something like this:
productsByNameMap.values() is the list with what you need, if the code has no errors.
if it helps please like and mark as correct as it may help others.
I am generating one pdf on click of a button and i want show the combined order line items in pdf. I am not updating any object.
I am getting following error while trying your approach
Field is not writeable: products__c.Quantity_c
Field is not writeable: products__c.TotalPrice__c
Is there any Other approach i can try.
Quantity_c , TotalPrice__c are formula fields in org