QPlanReader Class

Knowledge Center > Zuora CPQ > Zuora CPQ Development Resources > Zuora CPQ Component Library > Zuora CPQ Global Classes > CPQ X API > CPQ X Utilities > QPlanReader Class

QPlanReader Class

This functionality is in Limited Availability. We are actively soliciting feedback from a small set of early adopters.

This article describes the QPlanReader class, its global methods, and the related classes. The QPlanReader and the related classes are designed to be used by the services in CPQ X. You can use these classes to load existing QuoteRatePlan items in given quotes.

QPlanReader Global Methods

The QPlanReader class includes the following global methods.

Method Type Description
load(Id quoteId) List<QPlan>

Makes a QPlan List that represents all the QuoteRatePlan items in the Quote of the given quoteId.

load(QPlanReader.Settings settings) QPlanReader.Result

Makes a List of QPlans based on the settings parameter. See QPlanReader.Settings class below for the details.

Returns a QPlanReader.Result reference. See QPlanReader.Result Class below for the details.

Querying Custom Fields from Stored Products

As of Quotes 9.7, you can use the Store Existing Products Job to query custom fields from Zuora. See Store Custom Fields for Existing Products for the details.

The QPlanReader class uses the same field sets to indicate which fields should be loaded onto the CPQ X data model objects as the storeExistingProductsJob job. See the following table for the object and field set mapping. 

Salesforce Object Field Set Name
QuoteProductFeature__c CustomFeatureQueryFields
QuoteRatePlan__c CustomRatePlanQueryFields
QuoteRatePlanCharge__c CustomChargeQueryFields

QPlanReader.Result Class

The QPlanReader.Result class includes the following global method.

Method Type Description
getPlans() List<QPlan> Retrieves the List of QPlans based on the QuoteId specified in the QPlanReader.Settings class.

QPlanReader.Settings Class

QPlanReader.Settings Class Properties

The QPlanReader.Settings class includes the following global properties.

Property Type Required Description
quoteIds Set<Id> Yes A Set containing Ids of Quotes that the reader will load items from.
planLimit Integer No

Used to limit the number of records returned when querying for the Base Plans. If it is null, no limit is applied.

planOffset Integer No

Used to indicate the offset when querying for the Base Plans. If it is null, no offset is applied.

QPlanReader.Settings Global Methods

The QPlanReader.Settings class includes the following global methods.

Method Type Description
setPlanLimit(Integer planLimit) void

Sets the limit when querying for Base Plans under the specified Quote.

setPlanOffset(Integer planOffset) void Sets the offset when querying for Base Plans under the specified Quote.
setQuoteId(String quoteId) void Sets the quoteId of the Quote that the QPlanReader will read from.

Sample Code

Load QPlan List Based on the Specified quoteId

The following sample code shows how to get the QPlan List under a Quote based on the quoteId. 

public void test(){
    String amendQuoteId = 'quoteId_xxx1'; // Amendment quote with 1 added plan, 1 unmodified original plan, 1 original plan that has been updated and 1 original plan that had been flagged for removal
    List<QPlan> plans = zqu.QPlanReader.load(amendQuoteId);
    Map<String, Integer> countOfAmendmentTypes = new Map<String, Integer>();
    for (QPlan plan: plans) {
        String amendmentType = (String) plan.getAmendment().get('zqu__Type__c');
        if (!countOfAmendmentTypes.containsKey(amendmentType)) {
            countOfPlanTypes.put(amendmentType, 0);
        }
        Int newCount = countOfAmendmentTypes.get(amendmentType) + 1;
        countOfAmendmentTypes.put(amendmentType, newCount)
    }
    System.assertEquals(4, qPlans.size());
    System.assertEquals(1, countOfAmendmentTypes.get('NewProduct'));
    System.assertEquals(1, countOfAmendmentTypes.get('UpdateProduct'));
    System.assertEquals(1, countOfAmendmentTypes.get('RemoveProduct'));
    System.assertEquals(1, countOfAmendmentTypes.get('Original'));
}

Apply an offset to Load QPlans

The following sample code shows how to set the offset through QPlanReader.Setting class and apply it to load the QPlans starting from the offset under a given Quote. 

public void test(){
    String amendQuoteId = 'quoteId_xxx1'; // Amendment quote with 1 added plan, 1 unmodified original plan, 1 original plan that has been updated and 1 original plan that had been flagged for removal
    List<QPlan> plans = QPlanReader.load(amendQuoteId);
    System.assertEquals(4, plans.size());
     
    // Apply advanced settings
    QPlanReader.Settings readerSettings = new QPlanReader.Settings();
    readerSettings.setQuoteId(amendQuoteId);
    readerSettings.setPlanOffset(1);
    QPlanReader.Result readerResult = QPlanReader.load(readerSettings);
    List<QPlan> offsetPlans = readerResult.getPlans();
 
    // Verify that offset has been applied
    System.assertEquals(3, offsetPlans.size());
}

Apply a limit to Load QPlans

The following sample code shows how to set the limit through QPlanReader.Setting class and apply it to load the specified number of QPlans under a given Quote. 

public void test(){
    String amendQuoteId = 'quoteId_xxx1'; // Amendment quote with 1 added plan, 1 unmodified original plan, 1 original plan that has been updated and 1 original plan that had been flagged for removal
    List<QPlan> plans = QPlanReader.load(amendQuoteId);
    System.assertEquals(4, plans.size());
     
    // Apply advanced settings
    QPlanReader.Settings readerSettings = new QPlanReader.Settings();
    readerSettings.setQuoteId(amendQuoteId);
    readerSettings.setPlanLimit(1);
    QPlanReader.Result readerResult = QPlanReader.load(readerSettings);
    List<QPlan> limitedPlans = readerResult.getPlans();
 
    // Verify that limit has been applied
    System.assertEquals(1, limitedPlans.size());
}
Last modified

Tags

This page has no custom tags.

Classifications

(not set)