Happy Business Starts Here

Guru

Invalid api url exception in quote unit test in salesforce

***Zuora Config: invalid api url: null : Class.System.Url.<init>: line 35, column 1
Class.zqu.ZuoraConfig.ApiUrl.<init>: line 56, column 1
Class.zqu.ZuoraConfig.<init>: line 26, column 1
Class.zqu.ZuoraConfig.getInstance: line 16, column 1
Class.zqu.QuoteToBillingHandler: line 17, column 1
Class.zqu.GlobalClonedFieldDefinition.__sfdc_CHARGE_FIELDS: line 8, column 1
Class.zqu.ZQUtil.hasCustomClonedFieldDefinitionForCharge: line 954, column 1
Class.zqu.zQuoteUtilHelper.convert2ZCharge: line 1534, column 1
Class.zqu.zQuoteUtilHelper.convertProductRatePlanCharges: line 568, column 1
Class.zqu.zQuoteUtilHelper.getChargeGroup: line 392, column 1
Class.zqu.zQuoteUtil.getChargeGroup: line 14, column 1
Class.Z_TestFactory.addChargeToQuote: line 575, column 1

I am getting this error in a test class when I try to add a charge group I greated in code to a quote.

 

I am creating the product, rateplan, rateplan charge and rateplan charge tier.'

'

Then further down in log after I see

 

16:19:26.580 (8682975827)|SAVEPOINT_SET|[34]|SavepointValue0
16:19:26.580 (8683633129)|USER_DEBUG|[143]|DEBUG|***** (applyNewProductAmendments) PROCESSING zChargeGroup WITH GROUP ID 20181208T161932100Z *****
16:19:26.580 (8684372665)|DML_BEGIN|[81]|Op:Insert|Type:zqu__QuoteAmendment__c|Rows:1
16:19:26.703 (8703829801)|CODE_UNIT_STARTED|[EXTERNAL]|01q60000000LECt|zqu.QuoteAmendmentTrigger on QuoteAmendment trigger event BeforeInsert|__sfdc_trigger/zqu/QuoteAmendmentTrigger
16:19:26.703 (8708349028)|SYSTEM_MODE_ENTER|false
16:19:26.703 (8708373643)|SYSTEM_MODE_EXIT|false
16:19:26.703 (8708458573)|SYSTEM_MODE_ENTER|false
16:19:26.703 (8708813626)|SYSTEM_MODE_EXIT|false
16:19:26.703 (8708878166)|SYSTEM_MODE_ENTER|false
16:19:26.703 (8709774732)|SOQL_EXECUTE_BEGIN|[16]|Aggregations:0|SELECT Id, Is_Charge_Expired__c FROM Quote__c WHERE (Is_Charge_Expired__c = FALSE AND Is_Parent_Quote__c = FALSE AND ParentQuote__c = NULL AND id IN :tmpVar1)
16:19:26.703 (8718324382)|SOQL_EXECUTE_END|[16]|Rows:1
16:19:26.703 (8718584642)|DML_BEGIN|[21]|Op:Update|Type:zqu__Quote__c|Rows:1
16:19:26.703 (8730566172)|CODE_UNIT_STARTED|[EXTERNAL]|01q60000000LBaM|zqu.QuoteTrigger on Quote trigger event BeforeUpdate|__sfdc_trigger/zqu/QuoteTrigger

This is all in Zuora code.

 

Later in my test I have a callout - with a mocked response but that does not work because I get this error.

 

System.CalloutException: You have already created Savepoints. You cannot make callout after creating a Savepoint

Anyone have any idea what the 

invalid api url: null 

exception means???  I am not creating this SavePoint but Zuora is.

 

I really need to get these tests passing as I have to get my code coverage up to deploy a new feature ASAP.  This code is in a quote wizard page and needs to have a charge on the quote to get into the code under test.

 

If anyone has sample code for creating a single product and charge and adding it to a quote that works it would be good to compare. 

 

Any ideas?? @doyeli

 

Thanks,

Maggie

Maggie Longshore
2 REPLIES 2
Support SME

Re: Invalid api url exception in quote unit test in salesforce

HI @MaggieL

 

Regarding your following note

 

>>If anyone has sample code for creating a single product and charge and adding it to a quote that works it would be good to compare. 

 

The following thread has sample code  to add a valid product (from product catalog, created in UI) programatically to a Quote :

 

https://community.zuora.com/t5/Zuora-CPQ/Trying-to-add-ProductRatePlans-through-code-found-not-so/m-...

 

If you test your test class with a quote and product created in UI, does it work?

 

Thank you

Doyeli



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

Guru

Re: Invalid api url exception in quote unit test in salesforce

Thanks for your reply.

 

I tried the test with a quote and product rate plan created in the UI and I get the same result:

 

10:43:26.0 (1313225954)|SAVEPOINT_SET|[34]|SavepointValue0
10:43:26.0 (1313936855)|USER_DEBUG|[143]|DEBUG|***** (applyNewProductAmendments) PROCESSING zChargeGroup WITH GROUP ID 20181209T104332100Z *****
10:43:26.0 (1314834315)|DML_BEGIN|[81]|Op:Insert|Type:zqu__QuoteAmendment__c|Rows:1
10:43:26.325 (1325016049)|CODE_UNIT_STARTED|[EXTERNAL]|01q60000000LECt|zqu.QuoteAmendmentTrigger on QuoteAmendment trigger event BeforeInsert|__sfdc_trigger/zqu/QuoteAmendmentTrigger

The savepoint is still created so my test fails.

 

How can I avoid the savepoint being created?

 

A workaround would be to create my own charge group in code and skip calling any Zuora global methods but most of the fields are not writable.

 

Has anyone been able to unit test a callout when you need a quote to have a charge on it?

 

 

Maggie Longshore