Skip to main content

Send Quotes to Zuora Billing


Send Quotes to Zuora Billing

This topic describes how to use global methods to send quotes directly to Zuora.

sendToZBilling global method

Use the sendToZBilling global method to send quotes directly to Zuora. The syntax is:

sendToZBilling (quoteID, selectedZBillingAccountID, overrideZContacts, quoteFields, chargeFields)

The method supports the following parameters:

  • quoteID: The Salesforce ID of the quote. The quote can be of any type: New Subscription, Amendment, Renewal, or Cancellation.
  • selectedZBillingAccountID: Specify a scenario supported by Zuora Quotes for creating a subscription or amendment in Zuora. Specify one of the following scenarios:
    • selectedZBillingAccountID = New: Create a new customer and a new subscription in Zuora corresponding to the quote in Salesforce. Use this only when the quote subscription type is "New Subscription."
    • selectedZBillingAccountID = ID of the Customer in Zuora: Create a new subscription under the specified customer. Use this only when the quote subscription type is "New Subscription."
    • selectedZBillingAccountID: This value is ignored for amendment and renewal scenarios.
  • overrideZContacts: Specify whether to update the Zuora Bill To Contact and Sold To Contact with the the Salesforce Bill To Contact and Sold To Contact data. If the contacts do not exist in Zuora, this method call will create the corresponding contacts in Zuora.
  • quoteFields: This parameter is of type Map<String, String>. This is a map of a name-value for Salesforce and a Zuora custom field in a quote that you want to send to Zuora. The name of the field in Zuora must match the name of the field in Salesforce. You can add multiple fields and values in the map.
  • chargeFields: This parameter is of type Map<String, Map<String, String>>. This includes QuoteCharge ID – Field Name – Field Value information. The QuoteCharge records must be associated with the quote, and the field name must the Zuora subscription rate plan charge custom field name.

Sample code

The following is sample code for

<apex:page standardController="zqu__Quote__c" extensions="SendToZBillingPreviewController">    
   <apex:form >        
      <apex:pageMessages id="message"/>        
      <apex:pageBlock title="Quote Details" >            
         <apex:pageBlockButtons id="operations">                
            <apex:commandButton value="Send to Z-Billing" action="{!send}" reRender="operations, message"/>            
         <apex:pageBlockSection title="Basic Information" columns="2" rendered="{!record.zqu__SubscriptionType__c == 'New Subscription'}">                
            <apex:repeat value="{!$ObjectType.zqu__Quote__c.FieldSets.SamplePreviewBasicInfoSet}" var="previewBasicInfoField">                
               <apex:outputField value="{!record[previewBasicInfoField]}"/>                
         <apex:pageBlockSection title="Contact Information" columns="2" rendered="{!record.zqu__SubscriptionType__c == 'New Subscription'}">                
            <apex:repeat value="{!$ObjectType.zqu__Quote__c.FieldSets.SamplePreviewContactSet}" var="previewContactField">                
               <apex:outputField value="{!record[previewContactField]}"/>                
         <apex:pageBlockSection title="Subscription Information" columns="2">                
            <apex:repeat value="{!IF(record.zqu__SubscriptionType__c == 'New Subscription',
                $ObjectType.zqu__Quote__c.FieldSets.BasicInfoForAmendAndRenewalSet)}" var="previewSubscriptionField">                
               <apex:outputField value="{!record[previewSubscriptionField]}"/>                
         <apex:pageBlockSection title="Charge Groups" columns="1">                
            <apex:outputPanel >                     
               <apex:repeat value="{!chargeGroupList}" var="group">                         
                  <zqu:zChargeGroup chargeGroup="{!group}" editMode="false" />                    

public with sharing class SendToZBillingPreviewController
   public final List<zqu.ZChargeGroup> chargeGroupList {get; set;} 
   ​private final ApexPages.StandardController controller; 
   ​public SendToZBillingPreviewController(ApexPages.StandardController controller)
   ​   this.controller = controller; 
   ​   if (this.validate()) 
   ​   { 
   ​      try
   ​      { 
   ​         chargeGroupList = zqu.zQuoteUtil.getChargeGroups(this.controller.getRecord().Id);
         } catch(Exception e) { appendMessage(ApexPages.Severity.ERROR, e.getMessage()); } 
   public PageReference send()
   ​   { 
   ​      final String quoteId = this.controller.getRecord().Id; 
   ​      final Map<String, String> finalRes = zqu.zQuoteUtil.sendToZBilling(quoteId ,'New', true, null, null);
         ​String resultString = ''; 
      ​   for (String result : finalRes.values()) { resultString += result; } 
         ​appendMessage(ApexPages.Severity.INFO, resultString); 
      } catch(Exception e) { appendMessage(ApexPages.Severity.ERROR, e.getMessage()); } 
   ​   return null; 
   ​private Boolean validate() 
      ​if (null == this.controller.getRecord() || null == this.controller.getRecord().Id) 
         ​appendMessage(ApexPages.Severity.ERROR, 'Need to specify the id of quote for creating subscription.'); 
         ​return false; 
   ​   } 
   ​   return true;
   private static void appendMessage(ApexPages.Severity messageType, String message) 
      ApexPages.addMessage(new ApexPages.Message(messageType, message));


  • The API name of the fields in Salesforce must match the field names in Zuora.
  • You must create the field sets on the quote object. To do this, you must look in the sample page and add the same field set with the same name. Field sets create a specific section on the Visualforce page, which you can use to drag-and-drop fields from different related records. For our sample code, we have used field sets to show information related to quotes, as well as information related to the Bill To Contact and Sold To Contact.
  • The sample code uses the Zuora CPQ global methods to show the existing charges.
  • The result map return a success or failure code and corresponding messages. You can build your validation messages around these messages.

Using AJAX-Based calls with the global method

You can bypass the preview page and use AJAX-based webService calls to apex to send quotes directly to Zuora.

Sample code

The following is the Onclick JavaScript code behind a custom button on the Quote page.

var quoteId = '{!zqu__Quote__c.Id}';
var result = sforce.apex.execute("SendToZBillingAJAX", "callZQuoteGlobal", {quoteId : quoteId });
SendToZBillingAJAX global classglobal class SendToZBillingAJAX 
   webService static String callZQuoteGlobal(String quoteId)
      //Provide your logic to find the Billing Account Id with which you want to create Subscription
      //Or you can choose to always create a new Billing Account and Subscription
   ​   String selectedZBillingAccountId;         
      ​selectedZBillingAccountId = 'New';        
      ​Map<String,String> result = zqu.zQuoteUtil.sendToZBilling( quoteId , selectedZBillingAccountId , true, null, null );      
      if ( !result.containsKey('Success') ) return result.get('Failure');               
      else return result.get('Success');    


  • You can automate the new or existing Billing Account selection in the apex code, instead of using the selection in the user interface.
  • The sample code is an example of a different way of using the global method. You can customize the resulting alert message, or navigate to a new page.