Happy Business Starts Here

Zuora Alumni

Programmatically create Quote, send it to ZBilling, and create new Billing Account

How to programmatically create a new Quote, for an Account that does not exist in Zuora



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

6 REPLIES 6
Zuora Alumni

Re: Programmatically create Quote, send it to ZBilling, and create new Billing Account

Here is a code snippet that

  • executes anonymous block
  • future helper function
  • creates a new Account, Opportunity, BillTo
  • generates an invoice

 


Execute Anonymous

//new Account

Account a = new Account();

Datetime now = System.now();

a.Name = 'New Account - '+now;

insert a;

//new Contact

Contact c = new contact();

c.firstname='Test Contact';
c.lastname= ''+now;
c.AccountId=a.id;
c.email='test@email.com';
c.MailingState = 'California';
c.MailingPostalCode = '11111';
c.MailingCountry = 'United States';

insert c;

//new Opportunity
Opportunity o = new Opportunity();
o.name = 'Opportunity - '+now;
o.stagename = 'Closed Won';
o.CloseDate = Date.newinstance(now.year(),now.month(),now.day());
o.AccountId = a.id;

insert o;

System.debug(o);

//new Quote

zqu__Quote__c q = new zqu__Quote__c();
q.name = 'Quote '+now;
q.zqu__opportunity__c = o.id;
q.zqu__ValidUntil__c = Date.newinstance(now.year(),now.month(),now.day());
q.zqu__BillToContact__c = c.id;
q.zqu__SoldToContact__c = c.id;
q.zqu__StartDate__c = Date.newinstance(now.year(),now.month(),now.day());
q.zqu__PaymentMethod__c = 'Credit Card';
q.zqu__PaymentTerm__c = 'Net 30';
q.zqu__Currency__c = 'USD';
q.zqu__InitialTerm__c = 12;
q.zqu__RenewalTerm__c = 12;
q.zqu__GenerateInvoice__c = true;
q.zqu__ProcessPayment__c = true;

insert q;

//add existing product

zqu.zChargeGroup newChargeGroup = zqu.zQuoteUtil.getChargeGroup(q.Id,'a0p41000001ota7');
zqu.ZQuoteUtil.addChargeGroup(newChargeGroup);  

//send to zbilling

QuoteUtils.sendQuote2ZBilling(a.id,q.id);

Future helper

public class QuoteUtils {

    @future(callout=true)
    public static void sendQuote2ZBilling(Id sfdcAccountId, Id qid){

        List<zqu.zQuoteUtil.ZBillingQuoteCollection> quotes = new List<zqu.zQuoteUtil.ZBillingQuoteCollection>();

        zqu.zQuoteUtil.ZBillingQuoteCollection quote = new zqu.zQuoteUtil.ZBillingQuoteCollection();

        quote.sfdcAccountId = sfdcAccountId; // SFDC CRM Account ID

        quote.zAccountId = 'new'; // create Zuora Billing Account ID

        quote.quoteRequests = new List<zqu.zQuoteUtil.ZBillingQuoteRequest>();
        zqu.zQuoteUtil.ZBillingQuoteRequest req = new zqu.zQuoteUtil.ZBillingQuoteRequest();

        req.sfdcQuoteId = qid; // SFDC Quote ID
        quote.quoteRequests.add(req);

        quotes.add(quote);

        List<zqu.zQuoteUtil.zBillingResult> results = zqu.zQuoteUtil.sendToZBilling(quotes);

        for ( zqu.zQuoteUtil.zBillingResult result : results ) {
            System.debug('***** Result: QuoteId = ' + result.sfdcQuoteId + ', Success = ' + result.success + ', message = ' + result.message );
        }        

    }

}

 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Highlighted
Zuora Staff

Re: Programmatically create Quote, send it to ZBilling, and create new Billing Account

How to create bulk Accounts,contacts and opportunities and send to zuora for creating Billing Accounts

Savvy Scholar

Re: Programmatically create Quote, send it to ZBilling, and create new Billing Account

Hi adam

 

Thank you for sharing.

I have a question.

 

This hard coded id you use 'a0p41000001ota7'. What is that? Where did you get it? And which type of object is it?

 

all the best,

Support SME

Re: Programmatically create Quote, send it to ZBilling, and create new Billing Account

Hi @mfra99 'a0p41000001ota7' is the salesforce id of the created Quote

 

Thank you





SigNowBlue.png

 


If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Savvy Scholar

Re: Programmatically create Quote, send it to ZBilling, and create new Billing Account

Hi @doyeli 

Thanks for the reply.

I'm not interiorly convinced though.

 

zqu.zChargeGroup newChargeGroup = zqu.zQuoteUtil.getChargeGroup(q.Id,'a0p41000001ota7');

For the zqu.zQuoteUtil.getChargeGroup method, the first argument 'q.id' is the Quote id.

The second argument 'a0p41000001ota7' is not also the Quote id, no?

 

thanks,

Support SME

Re: Programmatically create Quote, send it to ZBilling, and create new Billing Account

Hi @mfra99 My Bad, sorry, a0p41000001ota7  should be the product Rateplan Id.

 

Thank you





SigNowBlue.png

 


If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √