Welcome to Zuora Product Documentation

Explore our rich library of product information

Commitment default value plugin sample code

Sample code for a plugin that sets default commitment type, payment term, and schedule amounts on quotes.

Sample code 1

The following example sets a default commitment type and payment term on the commitment, and sets a default amount on each generated commitment schedule.

global with sharing class MyCommitmentDefaultPlugin
        implements zqu.CommitmentDefaultValuesPlugin {

    global void initialize(
            zqu__Quote__c quote,
            zqu__Commitments__c commitment,
            List<zqu__CommitmentSchedule__c> schedules) {

        // Set default field values on the commitment
        if (commitment.zqu__CommitmentType__c == null) {
            commitment.zqu__CommitmentType__c = 'Revenue';
        }
        if (commitment.zqu__PaymentTerm__c == null) {
            commitment.zqu__PaymentTerm__c = 'Net 30';
        }

        // Set a default committed amount on each schedule
        for (zqu__CommitmentSchedule__c schedule : schedules) {
            if (schedule.zqu__Amount__c == null) {
                schedule.zqu__Amount__c = 1000;
            }
        }
    }
}

Sample code 2

This sample implements zqu.CommitmentDefaultValuesPlugin to set custom charge eligibility rule during commitment creation.

  • The initialize() method receives the quote, commitment, and commitment schedules.
  • It builds a JSON custom rule that matches charges where RatePlanCharge.InvoiceOwnerId equals the commitment owner account ID.
  • It limits applicability to the commitment account by setting zqu__ApplicableAccounts__c.
  • It enables custom charge filtering by setting zqu__ApplicableCharges__c to Custom Rule.
  • It serializes the rule JSON into zqu__ApplicableChargesCustomRule__c.
  • The quote and schedules parameters are not used in this example.

Although the comment refers to two specific plans, the current code contains one condition and matches the invoice owner account ID.

global class MyCommitmentDefaultValuesPlugin implements zqu.CommitmentDefaultValuesPlugin {
    global void initialize(
        zqu__Quote__c quote,
        zqu__Commitments__c commitment,
        List<zqu__CommitmentSchedule__c> schedules
    ) {
        Map<String, Object> ruleJson = new Map<String, Object>{
            'relation' => 'or',
            'conditions' => new List<Object>{
                new Map<String, Object>{
                    'field' => 'RatePlanCharge.InvoiceOwnerId',
                    'operator' => 'eq',
                    'value' => commitment.zqu__CommitmentOwnerAccountId__c
                }
            }
        };

        commitment.zqu__ApplicableAccounts__c = 'Commitment Account Only';
        commitment.zqu__ApplicableCharges__c = 'Custom Rule';
        commitment.zqu__ApplicableChargesCustomRule__c =
            JSON.serialize(ruleJson);
    }
}