I`m trying to call Continuation method from Apex that has
@AuraEnabled(continuation=true cacheable=true)
but getting next error:
Apex methods for continuation can not be invoked from a non-continuation action.
Here is the .js code that calls Apex:
proceedToBillingData() {
//unnecessary code skipped
getCart({ paymentData: JSON.stringify(this.pricingOption) })
.then(cartResult => {
getCCLogs(cartResult.logs);
this.isCartAvailable = true;
this.cartEncryptedId = cartResult.cartEncId;
return getTotalNetPriceFromSAP({ cartEncId: cartResult.cartEncId });
})
.then(sapResult => {
//TODO: obtain result from SAP
this.totalPrice = this.userFormatter.format(sapResult['ccrz__Price__c']);
this.vat = ((sapResult['ccrz__Price__c'] - this.pricingOption.exclVATPrice) / sapResult['ccrz__Price__c']) * 100;
this.isLoading = false;
})
.catch(error => {
console.error('error --- ', error);
this.isLoading = false;
this.isError = true;
this.errors = error.body.message;
});
}
getTotalNetPriceFromSAP() - is Continuation method
Apex code:
@AuraEnabled(continuation=true cacheable=true)
public static Map<String, Object> getTotalNetPriceFromSAP(final String cartEncId) {
//TODO: replace the code below with results from SAP callout using Continuation
List<ccrz__E_Cart__c> openCart = [SELECT ccrz__Account__r.SAP_Customer_Number__c,
(SELECT ccrz__Quantity__c FROM ccrz__E_CartItems__r)
FROM ccrz__E_Cart__c WHERE ccrz__EncryptedId__c = :cartEncId];
if (openCart[0].ccrz__E_CartItems__r.isEmpty()) {
throw CustomException.setErrorMessage(String.format(CustomException.NO_CART_ITEMS_BY_USER_ID, new String[] { currentUser.Id }));
}
try {
Continuation continuation = (Continuation) CC_EpayVatSimulate.startOrderSimulate(openCart[0]);
System.debug('getTotalNetPriceFromSAP --- ' + continuation);
return new Map<String, Object> { SObjectType.ccrz__E_CartItem__c.fields.ccrz__Price__c.Name => openCart[0].ccrz__E_CartItems__r[0].ccrz__Price__c };
} catch (Exception e) {
CustomException.setErrorMessage(e.getMessage());
}
}
The method is not being executed because of that error. If I remove the annotation params
(continuation=true cacheable=true)
it works, the method, not Continuation.
What could be the reason of this? Is the lwc action must be @wire only and not on-demand bcoz there is cacheable=true param?