Skip to main content

Generate Charge Segment records for Inflight Quotes - Multi Subscription Quoting

Zuora

Generate Charge Segment records for Inflight Quotes - Multi Subscription Quoting

After you turn on the Enable Charge Segment Metrics setting in Zuora Config > Quote Studio Settings > Admin Config, Charge Segments are generated for quotes once an Order Preview is sent to Zuora.

However, Inflight Quotes do not automatically have Charge Segments created. Inflight Quotes are existing, open quotes that have not yet been sent to Zuora. You can run the code snippet mentioned in this article to trigger the Preview call and generate Charge Segments for the child quotes of the given Parent Quote Ids.

Quotes that have already been sent to Zuora cannot be previewed through the Zuora APIs and therefore cannot have Charge Segments created.

There is a 4,000-character limit on the SOQL WHERE clause. For complex quotes with a high number of charges, updates, or ramps, consider limiting the number of Parent Quotes processed at one time.

  1. Open the Developer Console and select File > New > Apex Class.
    Alternatively, go to Setup and create a new Apex class.
  2. Name the class PreviewMSQBatchable.
    If you use a different name, ensure to update the class name in the code snippet provided in this article.
  3. Paste the code snippet provided in this article into the new class and click Save.
  4. In the Developer Console, click Debug > Execute Anonymous Window and paste the following three lines. These lines are also included in the commented section at the top of the larger code snippet.
     List<String> parentQuoteIds = new List<String>{'001xx000003DGAXAA4', 
     '001xx000003DGAXAA5', '001xx000003DGAXAA6'};
     BatchPreviewMSQ batchJob = new BatchPreviewMSQ(parentQuoteIds);
     Database.executeBatch(batchJob, 1); // Must process 1 quote per batch
    
  5. Enter the Parent Quote IDs you want to trigger into the SOQL query string.
  6. Ensure the quotes you include in the query string have the zqu__MSQ_AsyncRequestStatus__c field is empty.
  7. Execute the code in the Debug > Execute Anonymous Window.

Code snippet 

 
/**
 * Batch class to process multiple MSQ previews
 * To execute, paste the following three lines into Anonymous window:
 * 
 * List<String> parentQuoteIds = new List<String>{'001xx000003DGAXAA4', '001xx000003DGAXAA5', '001xx000003DGAXAA6'};
 * BatchPreviewMSQ batchJob = new BatchPreviewMSQ(parentQuoteIds);
 * Database.executeBatch(batchJob, 1); // Must process 1 quote per batch
 * 
 */
public class PreviewMSQBatchable implements Database.Batchable<String>, Database.AllowsCallouts {
    private List<String> parentQuoteIds;
    
    public PreviewMSQBatchable(List<String> parentQuoteIds) {
        this.parentQuoteIds = parentQuoteIds;
    }
    
    public List<String> start(Database.BatchableContext bc) {
        return parentQuoteIds;
    }
    
    public void execute(Database.BatchableContext bc, List<String> scope) {
        for (String parentQuoteId : scope) {
            System.debug(LoggingLevel.DEBUG, 'Record Id: ' + parentQuoteId);
            
            zqu.zQuoteUtil.SendToZuoraMSQRequest request = new zqu.zQuoteUtil.SendToZuoraMSQRequest();
            request.parentQuoteId = parentQuoteId;
            
            try {
                zqu.zQuoteUtil.SendToZuoraMSQResponse response = zqu.zQuoteUtil.previewMSQ(request);
                // Process response as needed
            } catch (Exception e) {
                // Handle exception
                System.debug(LoggingLevel.ERROR,'Error processing parentQuoteId: ' + parentQuoteId + '. Error: ' + e.getMessage());
            }
        }
    }
    
    public void finish(Database.BatchableContext bc) {}
}