QPlan Class

Knowledge Center > Zuora CPQ > Zuora CPQ Development Resources > Zuora CPQ Component Library > Zuora CPQ Global Classes > CPQ X API > CPQ X Models > QPlan Class

QPlan Class

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

This article describes the properties and the global methods in the QPlan class. The QPlan class:

  • Is designed to minimally represent the QuoteRatePlan objects.
  • Is used by the services in CPQ X and to replace the legacy QuoteProduct model.
  • Is used to interface with the QuoteRatePlan objects.
  • Contains utility methods to manage the quote amendment state.

QPlan Class Properties

The QPlan class includes the following properties.

Property Type Description
amendment QAmendment

The QAmendment object that this QPlan object is associated with. You can use it to determine the current state of the QPlan.

charges List<QCharge>

A List of QCharge objects under this QPlan.

features List<QuoteProductFeature__c>

A List of QuoteProductFeature objects associated with this QPlan.

Id String

The unique identifier of the QPlan instance.

originalPlan QPlan

Represents the original QuoteRatePlan associated with this QPlan.

voidAction Boolean

Indicates whether this QPlan is void.

QPlan Global Methods

The QPlan class includes the following global methods.

Method Type Description
deepClone(Boolean preserveId) QPlan

Returns a deeply cloned copy of the QPlan object. The preserveId parameter indicates whether or not to preserve the Id in the cloned object.

get(String fieldName) Object

Retrieves a field value from the QuoteRatePlan record.

getAmendment QAmendment

Retrieves the QAmendment record.

getCharges List<QCharge>

Retrieves a List of QCharge records that belong to this QPlan.

getFeatures List<QuoteProductFeature__c>

Retrieves the List of features associated with this QPlan.

getId String

Retrieves the unique identifier of the QPlan instance.

getRecord QuoteRatePlan__c

Retrieves the QuoteRatePlan instance that this QPlan represents.

isChanged Boolean

Returns true if the state of this QPlan record is different from what is last retrieved from DB.

isSaved Boolean

Returns true if this QPlan record has been inserted into the DB.

isVoidAction Boolean

Returns true if this plan represents an Amendment that is staged to be reverted upon save.

put(String fieldName, Object value) Object

Sets a field value on the QuoteRatePlan record. Returns the previous field value.

remove void

Calls to indicate that this QPlan represents an action to be removed. The result of this call depends on the state of the QPlan. See the State Changing Methods table for the call effects in different preconditions.

A successful call will enable the isChanged flag.

revert void

Reverts the QPlan to its original state. The result of this call depends on the state of the QPlan. See the State Changing Methods table for the call effects in different preconditions.

A successful call will enable the isChanged flag.

Sample Code

Get and Set Field Values

The following sample code shows how to set and retrieve field values on the QuoteRatePlan object through the QPlan.

public void test(zqu.QPlan plan) {
 
    // Get Initial Value
    System.assertEquals('My Value', (String) plan.get('MyPlanField__c') );
    System.assertEquals(false, plan.isChanged() );
 
    // Get Updated Value
    plan.put('MyPlanField__c', 'My New Value');
    System.assertEquals('My New Value', (String) plan.get('MyPlanField__c'));
    System.assertEquals(true, plan.isChanged() );
 
    // Validate Non-Editable Fields throw correct exception.
    try{
        plan.put('Name', 'My New Name');
        throw new UnthrownException('Should have thrown an exception on non-editable field.');
    } catch (zqu.NoneditableFieldException e) {
        // Successfully caught.
    } catch (Exception e) {
        throw new UnexpectedException('Incorrect Exception thrown: ' + e.getMessage());
    }
}

Get the List of QCharge Objects from a QPlan Instance

The following sample code shows how to retrieve the QCharge List from a QPlan instance.

public void test(zqu.QPlan plan) {
    // Count Charges
    List<zqu.QCharge> charges = plan.getCharges();
    System.assertEquals(3, charges.size() );
}

Remove a Product from a New Subscription Quote

The following sample code shows how to remove a product from a New Subscription Quote through the QPlan.

public void test(zqu.QPlan plan) {
    // Check Initial Type
    System.assertEquals('NewProduct', (String) plan.get('zqu__AmendmentType__c' );
    System.assertEquals(false, plan.isVoidAction() );
    // Remove Product
    plan.remove();
    System.assertEquals('NewProduct', (String) plan.get('zqu__AmendmentType__c' );
    System.assertEquals(true, plan.isVoidAction() );
}

Remove a Product from an Amendment Quote

The following sample code shows how to remove a product from an Amendment Quote through the QPlan.

 public void test(zqu.QPlan plan) {
    // Check Initial Type
    System.assertEquals('OriginalProduct', (String) plan.get('zqu__AmendmentType__c' );
 
    // Remove Product
    plan.remove();
    System.assertEquals('RemoveProduct', (String) plan.get('zqu__AmendmentType__c' );
}

Undo an UpdateProduct Amendment on an Amend Quote

The following sample code shows how to undo an UpdateProduct Amendment from an Amendment Quote through the QPlan.

 public void test(zqu.QPlan plan) { // Check Initial Type
 
    System.assertEquals('UpdateProduct', (String) plan.get('zqu__AmendmentType__c' );
    System.assertEquals(false, plan.isVoidAction() );
    System.assertEquals(10.0, plan.getCharges()[0].get('zqu__EffectivePrice__c') );
 
    // Undo Amendment
    plan.revert();
    System.assertEquals('OriginalProduct', (String) plan.get('zqu__AmendmentType__c' );
    System.assertEquals(true, plan.isVoidAction() );
    System.assertEquals(5.0, plan.getCharges()[0].get('zqu__EffectivePrice__c') );
}
Last modified

Tags

This page has no custom tags.

Classifications

(not set)