Skip to main content

Invoke an On-Demand Sync

Zuora

Invoke an On-Demand Sync

Overview

This topic includes sample Apex code snippets that invoke On-demand Sync sessions through the OnDemandSyncManager global class.

Sync Billing Accounts with Mapped to Zuora Customer Accounts

The following code invokes the On-demand Sync for specific billing accounts that are mapped to {[z_app}} customer accounts. You pass a set of billing account IDs, 15 or 18 character Salesforce IDs.

Set<Id> billingAccountIdSet = new Set<Id>();
populateBillingAccountIdSet(); // Add the billing account IDs to the set.  These billing accounts will be included in the On-demand Sync.
try
{
  Zuora.OnDemandSyncManager syncManager = new Zuora.OnDemandSyncManager();
  syncManager.syncObjectType = Zuora.OnDemandSyncManager.ObjectType.BILLING_ACCOUNT; 
  syncManager.syncObjectIdSet = billingAccountIdSet; 
  List<Zuora.SyncResult> syncResult = syncManager.sendRequest();
}
catch( Zuora.OnDemandSyncManager.OnDemandSyncException e )
{
  // Process On-demand Sync exception.
}

Sync Billing Accounts without a Mapped Salesforce Account

The following code invokes the On-demand Sync for Zuora customer accounts that are not mapped to Salesforce billing accounts. You pass a set of Zuora customer account IDs, the 32-character ID.

This is the scenario where the corresponding Salesforce Billing Account has not been created from a Zuora account, but the Zuora account is already associated with a CRM Account ID.

Set<String> zuoraAccountIdSet = new Set<String>();populateZuoraAccountIdSet(); // Add the Zuora account IDs to the set.  These Zuora accounts will be included in the On-demand Sync request.
try
{
  Zuora.OnDemandSyncManager syncManager = new Zuora.OnDemandSyncManager();
  syncManager.syncObjectType = Zuora.OnDemandSyncManager.ObjectType.BILLING_ACCOUNT; 
  syncManager.syncZuoraObjectIdSet = zuoraAccountIdSet; 
  List<Zuora.SyncResult> syncResult = syncManager.sendRequest();
}
catch( Zuora.OnDemandSyncManager.OnDemandSyncException e )
{
  // Process On-demand Sync exception.
}

Sync ZProducts Mapped to Zuora Products

The following code invokes the On-demand Sync for ZProducts that are mapped to Zuora products in the Product Catalog. Pass a set of ZProduct IDs. 

Set<Id> zProductIdSet = new Set<Id>();
populateProductIdSet(); // Add the product IDs to the set. These ZProducts will be included in the On-demand Sync request.
try
{
  Zuora.OnDemandSyncManager syncManager = new Zuora.OnDemandSyncManager();
  syncManager.syncObjectType = Zuora.OnDemandSyncManager.ObjectType.ZPRODUCT; 
  syncManager.syncObjectIdSet = zProductIdSet; 
  List<Zuora.SyncResult> syncResult = syncManager.sendRequest();
}
catch( Zuora.OnDemandSyncManager.OnDemandSyncException e )
{
  // If Zuora Quotes is not installed, an OnDemandSyncException will be thrown indicating the error.
}

Sync a Zuora Product Not Mapped to a Zuora Product in Zuora Quotes

The following code invokes the On-demand Sync for Zuora Products in the Product Catalog that are not mapped to a ZProducts. Pass a set of Zuora Product IDs (the 32-character ID). After the sync, new ZProducts will be created in Salesforce.

Set<String> zuoraProductIdSet = new Set<String>();
populateZuoraProductIdSet(); // Add the product IDs to the set. These ZProducts will be included in the On-demand Sync request.
try
{
  Zuora.OnDemandSyncManager syncManager = new Zuora.OnDemandSyncManager();
  syncManager.syncObjectType = Zuora.OnDemandSyncManager.ObjectType.ZPRODUCT; 
  syncManager.syncZuoraObjectIdSet = zuoraProductIdSet; 
  List<Zuora.SyncResult> syncResult = syncManager.sendRequest();
}
catch( Zuora.OnDemandSyncManager.OnDemandSyncException e )
{
  // If Zuora Quotes is not installed, an OnDemandSyncException will be thrown indicating the error.
}