- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
I am trying to add specific ProductRatePlans on an existing Quote through the code and found this useful article. The article has an example at the end of the page which talks about how to "Add a Product to a quote with a specific rate plan". For some reason this idea is not scalable when you are adding ProductRatePlans from multiple Products and requires a lot of looping. Is there a better way to add specific ProductRatePlans?
Vinar
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thanks, @Hina, and @doyeli for helping me with this. I was able to add Product Rate Plans using the below code snippet.
Id quoteId = 'xxxxxxxxxxxxxxxx'; List<Id> prpIds = new List<Id>(); prpIds.add(productRatePlanId); prpIds.add(productRatePlanId); // Get charge groups ready to be added List<zqu.ZChargeGroup> chargeGroups = zqu.ZQuoteUtil.getChargeGroups(quoteId, prpIds); 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 = '123'; zqu.zQuoteUtil.calculateChargesOnQuantityChange(chargeGroup.zCharges); charge.discount = '36'; zqu.zQuoteUtil.calculateChargesOnDiscountChange(chargeGroup.zCharges); } } zqu.ZQuoteUtil.addChargeGroups(chargeGroups);
Vinar
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Trying to add ProductRatePlans through code; found not so efficient method, is there a better wa
Hi @vinar,
I do have a ticket from you for the same issue and I will update this thread after my investigation towards it.
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thanks, @Hina, and @doyeli for helping me with this. I was able to add Product Rate Plans using the below code snippet.
Id quoteId = 'xxxxxxxxxxxxxxxx'; List<Id> prpIds = new List<Id>(); prpIds.add(productRatePlanId); prpIds.add(productRatePlanId); // Get charge groups ready to be added List<zqu.ZChargeGroup> chargeGroups = zqu.ZQuoteUtil.getChargeGroups(quoteId, prpIds); 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 = '123'; zqu.zQuoteUtil.calculateChargesOnQuantityChange(chargeGroup.zCharges); charge.discount = '36'; zqu.zQuoteUtil.calculateChargesOnDiscountChange(chargeGroup.zCharges); } } zqu.ZQuoteUtil.addChargeGroups(chargeGroups);
Vinar
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Trying to add ProductRatePlans through code; found not so efficient method, is there a better wa
Thanks @vinar
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Trying to add ProductRatePlans through code; found not so efficient method, is there a better wa
Thank you so much @vinar 🙂
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Trying to add ProductRatePlans through code; found not so efficient method, is there a better wa
Just to enhance on what @vinar has documented earlier, here is an example code to set/populate a custom field value as part of adding charges programatically
zqu.GlobalCustomFieldDefinition.CHARGE_FIELDS = new Set<String>{'test_data__c'};
List<Id> prpIds = new List<Id>();
prpIds.add('a0Rf4000001NnOS');
//prpIds.add('a0j1D00000080qsQAA');
// Get charge groups ready to be added
List<zqu.ZChargeGroup> chargeGroups = zqu.ZQuoteUtil.getChargeGroups('a0if400000BqP3UAAV', prpIds);
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 = '123';
zqu.zQuoteUtil.calculateChargesOnQuantityChange(chargeGroup.zCharges);
}
// Read a custom field on zCharge
charge.chargeObject.get('test_data__c');
// Update a custom field on zCharg
charge.chargeObject.put('test_data__c', 'test1');
}
zqu.ZQuoteUtil.addChargeGroups(chargeGroups);
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: Trying to add ProductRatePlans through code; found not so efficient method, is there a better wa
this is a great example, thanks @doyeli
Vinar