Skip to main content

SubscriptionValidator Class

Zuora

SubscriptionValidator Class

This article describes the SubscriptionValidator class, its global methods, and the related classes. The SubscriptionValidator class provides the global methods for programmatically validating the SteelBrick subscriptions and backfilling missing references found during the validation process. This class can also be used wherever it is required to perform validation and backfill operations.

SubscriptionValidator Global Methods

The SubscriptionValidator class includes the following global methods.

Method Type Description
validate(List<Id> subscriptionIds, Boolean updateData)

List<Result>

Performs the validation or the backfill of the missing references on a list of Subscriptions represented by the List of Subscription Ids. If the Boolean parameter updateData is false, the method performs the validation task and return the validation results. Otherwise, it performs the backfill process. The return value contains a success indicator along with related metadata. 

The parameter subscriptionIds is a List of Subscription Ids that represents the SteelBrick Subscriptions. The parameter updateData is a Boolean used to indicate whether the method performs the validation task or the backfill task.

The method returns a List of SubscriptionValidator.Result objects. See the SubscriptionValidator.Result class below for details.

SubscriptionValidator.Result Class

SubscriptionValidator.Result is a wrapper class that contains the information to indicate the result of the validation process for Subscriptions. It contains the following properties.

Property Type Description
success Boolean Indicates the success status of the operation.
message String Contains error code along with error or validation message returned by the API call. If the success indicator is false, the appropriate error message is filled into this property.
subscriptionId Id The Salesforce Id of the SteelBrick Subscription that is validated.
isSentToZuora Boolean Indicates whether the Subscription is sent to Zuora already.
subscriptionState State

Is an enum describing the state of the Subscription record after the validation process. Possible values are:

IGNORED

NOT_SENT

SENT_AND_VALID

SENT_AND_AMENDMENT_DATA_MISSING

SENT_AND_RATEPLAN_DATA_MISSING

SENT_AND_RATEPLAN_DATA_INVALID

SENT_AND_AMENDMENT_DATA_FIXED

SENT_AND_RATEPLAN_DATA_FIXED

Sample Code

Validate - New Contract with New Subscription Not Sent To Zuora

// In this use case we are assuming that the contract is a brand new contract with one subscription which is not sent to Zuora yet.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwVqUAI');
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results)); 
 
Output:
[
  {
    "success": true,
    "subscriptionState": "NOT_SENT",
    "subscriptionId": "a1F6A000001rwVqUAI",
    "message": null,
    "isSentToZuora": false
  }
]

Validate - New Contract with New Subscription Sent To Zuora

// In this use case we are assuming that the contract is sent to Zuora already and the new subscription already exists.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwWyUAI');
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the RatePlanId & RatePlanChargeId and then run the validation process again.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwWyUAI');
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": false,
    "subscriptionState": "SENT_AND_RATEPLAN_DATA_MISSING",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": "Rateplan Id: BLANK, Actual value should be 2c92c8fa650e62b7016512cf608e0269.",
    "isSentToZuora": true
  }
]

Validate - Contract with Add Product Amendment Sent To Zuora

// In this use case we are assuming that a new product was added to the existing subscription and the subscription is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwWyUAI');                                          // Base Subscription - Original Product.
subscriptionIds.add('a1F6A000001rwX3UAI');                                          // Amendment - New Product Amendment.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwX3UAI",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the Amendment Code & Amendment Id of the newly added product record and then run the validation process again.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": false,
    "subscriptionState": "SENT_AND_AMENDMENT_DATA_MISSING",
    "subscriptionId": "a1F6A000001rwX3UAI",
    "message": "Amendment Code: BLANK, Actual value should be A-AM00000029.",
    "isSentToZuora": true
  }
]
 
// Manually remove the RatePlanId & RatePlanChargeId of the newly added product record and then run the validation process again.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": false,
    "subscriptionState": "SENT_AND_RATEPLAN_DATA_MISSING",
    "subscriptionId": "a1F6A000001rwX3UAI",
    "message": "Rateplan Id: BLANK, Actual value should be 2c92c8fa650e62b7016512cf608e0269.",
    "isSentToZuora": true
  }
]

Validate - Contract With Update Product Amendment Sent To Zuora

// In this use case we are assuming that existing products were amended and the subscription is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwWyUAI');                                          // Base Subscription - Original Product.
subscriptionIds.add('a1F6A000001rwX3UAI');                                          // Amendment - New Product Amendment.
subscriptionIds.add('a1F6A000001rwXDUAY');                                          // Amendment - Update Product Amendment.
subscriptionIds.add('a1F6A000001rwXEUAY');                                          // Amendment - Update Product Amendment.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results)); 
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwX3UAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwXDUAY",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwXEUAY",
    "message": null,
    "isSentToZuora": true
  }
]

Validate - Contract With Remove Product Amendment Sent To Zuora

// In this use case we are assuming that existing products were amended and the subscription is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwWyUAI');                                          // Base Subscription - Original Product.
subscriptionIds.add('a1F6A000001rwX3UAI');                                          // Amendment - New Product Amendment.
subscriptionIds.add('a1F6A000001rwXDUAY');                                          // Amendment - Update Product Amendment.
subscriptionIds.add('a1F6A000001rwXEUAY');                                          // Amendment - Update Product Amendment.
subscriptionIds.add('a1F6A000001rwesUAA');                                          // Amendment - Remove Product Amendment.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results)); 
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwWyUAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwX3UAI",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwXDUAY",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwXEUAY",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwesUAA",
    "message": null,
    "isSentToZuora": true
  }
]

Validate - Contract With Renewal Subscription Sent To Zuora

// In this use case we are assuming that a new renewal contract is created from an existing contract with 2 products in it and is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001rwhDUAQ');                                          // Renewed Subscription - Original Product.
subscriptionIds.add('a1F6A000001rwhEUAQ');                                          // Renewed Subscription - Original Product.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwhDUAQ",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001rwhEUAQ",
    "message": null,
    "isSentToZuora": true
  }
]

Validate - Contract with Subscription that is Ignored to Send To Zuora

// In this use case we are assuming that the contract has 3 subscriptions and out of which 2 subscriptions are sent to Zuora and one is ignored.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F3u000003RxKs');        // Sent to zuora.
subscriptionIds.add('a1F3u000003RxKt');        // Ignored.
subscriptionIds.add('a1F3u000003RxKu');        // Sent to zuora.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, false);
System.debug(JSON.serialize(results));

Output:
[
 {
   "success": true,
   "subscriptionState": "SENT_AND_VALID",
   "subscriptionId": "a1F3u000003RxKsEAK",
   "message": null,
   "isSentToZuora": true
 },
 {
   "success": true,
   "subscriptionState": "IGNORED",
   "subscriptionId": "a1F3u000003RxKtEAK",
   "message": "Subscription is flagged to skip submission",
   "isSentToZuora": false
 },
 {
   "success": true,
   "subscriptionState": "SENT_AND_VALID",
   "subscriptionId": "a1F3u000003RxKuEAK",
   "message": null,
   "isSentToZuora": true
 }
]

Backfill - New Contract With New Subscription Not Sent To Zuora

// In this use case we are assuming that the contract is a brand new contract with one subscription which is not sent to Zuora yet.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001s1m8UAA');
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, true);
System.debug(JSON.serialize(results)); 
 
Output:
[
  {
    "success": true,
    "subscriptionState": "NOT_SENT",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": false
  }
]

Backfill - New Contract With New Subscription Sent To Zuora


// In this use case we are assuming that the contract is sent to Zuora already and the new subscription already exists.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001s1m8UAA');
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, true);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the RatePlanId & RatePlanChargeId and then run the back fill process again.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001s1m8UAA');
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, true);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_RATEPLAN_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Run the validation process again after the data fill.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  }
]

Backfill - Contract With Add Product Amendment Sent To Zuora

// In this use case we are assuming that a new product was added to the existing subscription and the subscription is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001s1m8UAA');                                          // Base Subscription - Original Product.
subscriptionIds.add('a1F6A000001s1m9UAA');                                          // Amendment - New Product Amendment.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, true);
System.debug(JSON.serialize(results));
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the Amendment Code & Amendment Id of the newly added product record and then run the back fill process.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_AMENDMENT_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the RatePlanId & RatePlanChargeId of the newly added product record and then run the back fill process again.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_RATEPLAN_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  }
]

Backfill - Contract With Update Product Amendment Sent To Zuora

// In this use case we are assuming that existing products were amended and the subscription is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001s1m8UAA');                                          // Base Subscription - Original Product.
subscriptionIds.add('a1F6A000001s1m9UAA');                                          // Amendment - New Product Amendment.
subscriptionIds.add('a1F6A000001s1q0UAA');                                          // Amendment - Update Product Amendment.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, true);
System.debug(JSON.serialize(results)); 
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1q0UAA",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the Amendment Code & Amendment Id of the update product amendment record and then run the back fill process.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_AMENDMENT_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1q0UAA",
    "message": null,
    "isSentToZuora": true
  }
]
  
// Manually remove the RatePlanId & RatePlanChargeId of the update product amendment record and then run the back fill process again.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_RATEPLAN_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1q0UAA",
    "message": null,
    "isSentToZuora": true
  }
]

Backfill - Contract With Remove Product Amendment Sent To Zuora

// In this use case we are assuming that existing products were amended and the subscription is already sent to Zuora.
List<Id> subscriptionIds = new List<Id>();
subscriptionIds.add('a1F6A000001s1m8UAA');                                          // Base Subscription - Original Product.
subscriptionIds.add('a1F6A000001s1m9UAA');                                          // Amendment - New Product Amendment.
subscriptionIds.add('a1F6A000001s1q0UAA');                                          // Amendment - Update Product Amendment.
subscriptionIds.add('a1F6A000001s1qKUAQ');                                          // Amendment - Remove Product Amendment.
SubscriptionValidator validator = new SubscriptionValidator();
List<SubscriptionValidator.Result> results = validator.validate(subscriptionIds, true);
System.debug(JSON.serialize(results)); 
 
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1q0UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1qKUAQ",
    "message": null,
    "isSentToZuora": true
  }
]
 
// Manually remove the Amendment Code & Amendment Id of the remove product amendment record and then run the back fill process.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1q0UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_AMENDMENT_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1qKUAQ",
    "message": null,
    "isSentToZuora": true
  }
]
  
// Manually remove the RatePlanId & RatePlanChargeId of the update product amendment record and then run the back fill process again.
Output:
[
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m8UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1m9UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_VALID",
    "subscriptionId": "a1F6A000001s1q0UAA",
    "message": null,
    "isSentToZuora": true
  },
  {
    "success": true,
    "subscriptionState": "SENT_AND_RATEPLAN_DATA_FIXED",
    "subscriptionId": "a1F6A000001s1qKUAQ",
    "message": null,
    "isSentToZuora": true
  }
]