- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
How to clone multiple quote and calculate the total amount?
HI Guys,
I am working on quote clone process and after that, I am using
ExtendedZQuoteUtil.addChargeGroup(subQuote, productRatePlan, chargeGroupOfMasterQuote); to calculate the quantity and total. But if you look at the code it is only processing one record at a time. I want to process this for multiple records. Is there any method or class that I use to process multiple quotes together?
I tried to use in this way
public void addParentChargeGroups(Map<Id, Set<Id>> parentQuoteToAccountIds) {
Map<Id, zqu__ProductRatePlanCharge__c> productRatePlanCharge = getProductRatePlanCharge(getAllProductRatePlan(parentQuoteToAccountIds.KeySet()));
for(Id quoteId: parentQuoteToAccountIds.KeySet()){
List<zqu.ZChargeGroup> chargeGroups = zqu.zQuoteUtil.getChargeGroups(quoteId);
for (zqu.ZChargeGroup chargeGroup : chargeGroups) {
if (chargeGroup.zCharges.size() > 0) {
String productRatePlanChargeId = chargeGroup.zCharges[0].PRODUCT_RATE_PLAN_CHARGE_SFDC_ID;
if(productRatePlanCharge.containsKey(productRatePlanChargeId) ){
addChargeGroup(parentQuoteToAccountIds.get(quoteId), productRatePlanCharge.get(productRatePlanChargeId).zqu__ProductRatePlan__c, chargeGroup); // need to investigate which are performing API calls and those that are need to be bulkified
}
}
}
}
}
private Set<Id> getAllProductRatePlan(Set<Id> parentZQuoteIds){
Set<Id> productRatePlanId = new Set<Id>();
for(Id quoteId: parentZQuoteIds){
List<zqu.ZChargeGroup> chargeGroups = zqu.zQuoteUtil.getChargeGroups(quoteId);
for (zqu.ZChargeGroup chargeGroup : chargeGroups) {
if (chargeGroup.zCharges.size() > 0) {
Id productRatePlanChargeId = chargeGroup.zCharges[0].PRODUCT_RATE_PLAN_CHARGE_SFDC_ID;
productRatePlanId.add(productRatePlanChargeId);
}
}
}
return productRatePlanId;
}
private Map<Id, zqu__ProductRatePlanCharge__c> getProductRatePlanCharge(Set<Id> productChargeIds) {
return new Map<Id, zqu__ProductRatePlanCharge__c>([SELECT Id, zqu__ProductRatePlan__c
FROM zqu__ProductRatePlanCharge__c
WHERE Id IN: productChargeIds]);
}
private void addChargeGroup(Set<Id> subQuoteIds, Id productRatePlanId, zqu.ZChargeGroup chargeGroupOfMasterQuote) {
for(Id subQuoteId: subQuoteIds){
zqu.zChargeGroup chargeGroupOfSubQuote = zqu.zQuoteUtil.getChargeGroup(subQuoteId, productRatePlanId);
copyCharges(chargeGroupOfMasterQuote, chargeGroupOfSubQuote);
zqu.zQuoteUtil.addChargeGroup(chargeGroupOfSubQuote);
}
}
private void copyCharges(zqu.ZChargeGroup srcChargeGroup, zqu.ZChargeGroup destChargeGroup) {
// Set Quantity to fix the tier.
for (zqu.zCharge srcZCharge : srcChargeGroup.zCharges) {
for (zqu.zCharge destZCharge : destChargeGroup.zCharges) {
if (destZCharge.PRODUCT_RATE_PLAN_CHARGE_SFDC_ID.equalsIgnoreCase(srcZCharge.PRODUCT_RATE_PLAN_CHARGE_SFDC_ID)) {
destZCharge.QUANTITY = srcZCharge.QUANTITY; // TODO quantity should default from the accounts pupil numbers
}
}
}
zqu.zQuoteUtil.calculateChargesOnQuantityChange(destChargeGroup.zCharges);
// Set Total.
for (zqu.zCharge srcZCharge : srcChargeGroup.zCharges) {
for (zqu.zCharge destZCharge : destChargeGroup.zCharges) {
if (destZCharge.PRODUCT_RATE_PLAN_CHARGE_SFDC_ID.equalsIgnoreCase(srcZCharge.PRODUCT_RATE_PLAN_CHARGE_SFDC_ID)) {
destZCharge.TOTAL = srcZCharge.TOTAL;
}
}
}
zqu.zQuoteUtil.calculateChargesOnTotalChange(destChargeGroup.zCharges);
}
but this this giving soql 101 error in salesforce. Any help on this to work with bulk records?
https://github.com/zuora/Z-Force/blob/master/QuoteSplit/src/classes/ExtendedZQuoteUtil.cls