- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Best method to trigger the updates on both discount and quantity using zQuoteUtil Class
Question:
When adding zChargeGroups to a to a quote using code I want to set the discount and quantity on the charges. Before the changes are actually applied I need to trigger a recalculation using one of the following methods:
calculateChargesOnDiscountChange
calculateChargesOnEffectivePriceChange
calculateChargesOnQuantityChange
calculateChargesOnTotalChange
The problem is that I can only pick one, and in my case, I need to trigger the updates on both discount and quantity. Can you recommend an approach for this?
Answer:
Below is the sample code to trigger the updates on both discount and quantity.
List<Id> prpIds = new List<Id>();
prpIds.add('a0r6F00000GQxxx'); //Product rate plan ID
// Get charge groups ready to be added
List<zqu.ZChargeGroup> chargeGroups = zqu.ZQuoteUtil.getChargeGroups('a186F000005Dxxx', prpIds); //Quote ID
for (zqu.zChargeGroup chargeGroup : chargeGroups) {
// Update chargeGroup with new quantity and discount
List<zqu.zCharge> charges = chargeGroup.zCharges;
zqu.zCharge charge = charges[0];
if (charge.IsQuantityEditable) {
charge.quantity = '28';
zqu.zQuoteUtil.calculateChargesOnQuantityChange(chargeGroup.zCharges);
charge.discount = '28';
zqu.zQuoteUtil.calculateChargesOnDiscountChange(chargeGroup.zCharges);
}
}
zqu.ZQuoteUtil.addChargeGroups(chargeGroups);
Sample record updated from the above code:
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √