Skip to main content

On-Demand Sync Trigger


On-Demand Sync Trigger


This article presents a custom sample code that triggers an On-Demand Sync on a Zuora account after a quote is sent to Zuora.

Add an After Update Trigger

When your user sends a quote to Zuora, Zuora creates a subscription and populate both Zuora Subscription ID and Zuora Account ID into the Quote object. You can then automatically trigger an On-demand Sync on the Zuora account so that the user can see the new subscription on the Account Detail page in Zuora Quotes.

To add the sample trigger in the Quote object:

  1. Navigate to Setup > App Setup > Create > Objects.
  2. Click Quotes in the Custom Objects list.
  3. In the Triggers section, click New .
  4. Copy the following code for the QuoteOnDemandSyncTrigger trigger, into the Apex Trigger window, then click Save.
trigger QuoteOnDemandSyncTrigger on Quote__c ( after update ) 
  if ( Trigger.isUpdate && Trigger.isAfter )
    List<zqu__Quote__c> quotes =; 
    List<zqu__Quote__c> oldQuotes = Trigger.old; 
    Map<Id, String> idSubMap = new Map<Id, String>();
    for ( zqu__Quote__c oldQuote : oldQuotes )
      idSubMap.put(, oldQuote.zqu__ZuoraSubscriptionID__c );
    Set<String> zuoraAccountIdSet = new Set<String>();
    for ( zqu__Quote__c quote : quotes )
      String oldSubscriptionId = idSubMap.get( );
      String newSubscriptionId = quote.zqu__ZuoraSubscriptionID__c; 
      System.debug( 'Old subscription id = ' + oldSubscriptionId + ', newSubscripitonId = ' + newSubscriptionId );
      if ( oldSubscriptionId != newSubscriptionId )
        zuoraAccountIdSet.add( quote.zqu__ZuoraAccountID__c);
    if ( zuoraAccountIdSet.size() > 0 )
      Zuora.OnDemandSyncManager syncManager = new Zuora.OnDemandSyncManager();
      syncManager.syncZuoraObjectIdSet = zuoraAccountIdSet; 

Test the Code

After the Quote trigger is updated, test the trigger as below.

To test the trigger sample code:

  1. Create a new quote and send it to Zuora. This creates a subscription in Z-Billing.
  2. After a few minutes, return to the opportunity and click the Account Name you used for the quote above. On the Account detail page, you should see a new subscription in the Subscriptions related list. This subscription is a result of the On-demand Sync invoked by the quote trigger.