Skip to main content
2 of 2
added 161 characters in body
sfdcfox
  • 501.7k
  • 21
  • 473
  • 828

Apex Error: The callout was unsuccessful after 4 attempts

I really need help with this error. I am trying to call a global method of a managed package in my apex class. I am calling this method in the Process builder on creation of some X record. Whenever my Workflow executes (on X creation), I end up receiving the error: "An Apex error occurred: zqu.RestRequest.RestRequestException: The callout was unsuccessful after 4 attempts: You have uncommitted work pending. Please commit or rollback before calling out". The same code works perfectly when I execute in Anonymous window.

global class executeSendToZbilling {
    @InvocableMethod global static void method() {
        List<zqu.zQuoteUtil.ZBillingQuoteCollection> quotes = new        List<zqu.zQuoteUtil.ZBillingQuoteCollection>();
        zqu__Quote__c cancQuote= [SELECT ID, zqu__Account__c, zqu__ZuoraAccountID__c, zqu__Status__c FROM zqu__Quote__c WHERE zqu__Status__c= 'New' AND zqu__SubscriptionType__c = 'Cancel Subscription' AND CreatedDate = TODAY];
        zqu.zQuoteUtil.ZBillingQuoteCollection quote = new zqu.zQuoteUtil.ZBillingQuoteCollection();
        quote.sfdcAccountId = cancquote.zqu__Account__c; // SFDC CRM Account ID
        quote.zAccountId = cancQuote.zqu__ZuoraAccountID__c; // Zuora Billing Account ID
        quote.quoteRequests = new List<zqu.zQuoteUtil.ZBillingQuoteRequest>();
        zqu.zQuoteUtil.ZBillingQuoteRequest req = new    zqu.zQuoteUtil.ZBillingQuoteRequest();
        req.sfdcQuoteId = cancquote.ID; // SFDC Quote ID
        quote.quoteRequests.add(req);
        
        quotes.add(quote);
        
        List<zqu.zQuoteUtil.zBillingResult> results =   zqu.zQuoteUtil.sendToZBilling(quotes); /*The above mentioned error is here*/
        for ( zqu.zQuoteUtil.zBillingResult result : results ) {
            System.debug( 'Result: QuoteId = ' + result.sfdcQuoteId + ', Success = ' + result.success + ', message = ' + result.message );
        }
    }
}

I am not able to figure out whats the error. Any suggestions please. Thanks in advance!!

Kanikala
  • 197
  • 1
  • 2
  • 22