Skip to main content

QTier Class

Zuora

QTier Class

This article describes the global methods in the QTier class. The QTier class:

  • Is designed to minimally represent the QuoteChargeTier objects.
  • Is used to interface with QuoteChargeTier objects in the CPQ X.
  • Contains utility methods for setting tier level fields.
  • Handles recalculation upon field value changes.

QTier Global Methods

The QTier class includes the following global methods.

Method Type Description
get(String fieldName) Object

Retrieves a field value from the QuoteChargeTier record.

getRecord QuoteCharge_Tier__c Retrieves the QuoteChargeTier record that the QTier represents.
isChanged Boolean

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

isSaved Boolean

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

put(String fieldName, Object value) Object

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

Recalculation Table

A put() operation on certain fields will trigger a recalculation process. These trigger conditions are detailed in the table below

When any of these fields are not valid for a particular Charge Model or Charge Type, slight modifications to these formulas will be made to accommodate.

Field Changed Action(s) Taken Recalculation Logic
Discount__c Recalculation is applied

Effective Price = List Price - (List Price * (Discount / 100))

Effective_Price__c Recalculation is applied

Effective Price = List Price - (List Price * (Discount / 100))

Price__c Recalculation is applied Discount = (ListPrice - Effective Price) * (100 / List Price)

Sample Code

Get and Set fields from a Quote Charge Tier

The following sample code shows how to set and retrieve field values on the QuoteChargeTier record through the QTier.

public void test(zqu.QTier tier) {
    // Get Initial Value
    System.assertEquals('My Value', (String) tier.get('MyTierField__c'));
    System.assertEquals(false, tier.isChanged());
  
    // Get Updated Value
    tier.put('MyTierField__c', 'My New Value');
    System.assertEquals('My New Value', (String) tier.get('MyTierField__c'));
    System.assertEquals(true, plan.isChanged());
}

Update a Field that Results in a Recalculation

The following sample code shows how the recalculation is triggered when updating the Discount__c field value.

public void test(zqu.QTier tier) {
    // Assert Initial values
    System.assertEquals(10, (Double) tier.get('zqu__Price__c'));
    System.assertEquals(0, (Double) tier.get('zqu__Discount__c'));
    System.assertEquals(10, (Double) tier.get('zqu__Effective_Price__c'));
    System.assert(Equalsfalse, tier.isChanged());
  
    // Update value and test recalculation
    tier.put('zqu__Discount__c', 50);
    System.assertEquals(10, (Double) tier.get('zqu__Price__c'));
    System.assertEquals(50, (Double) tier.get('zqu__Discount__c'));
    System.assertEquals(true, plan.isChanged());
    System.assertEquals(5, (Double) tier.get('zqu__Effective_Price__c'));
}