0

I am attempting to create a Quick Action using an LWC to submit a Quote for Approval. I had this done in APEX and Visualforce however I want to convert it to LWC. I found that in order to use Quick Action for an LWC I need to use @api invoke() however I am not sure how you can use the invoke and call a Apex Class.

What Ideally I want to happen is to have Validations Messages display on the Screen. If No Validation the display Approval Submitted.

HTML

<template>
<div class="toast toast_hide" style="height:4rem" data-id="toast">
    <div class="slds-notify_container slds-is-relative">
        <div class={notifyClasses} role="status">
            <span class="slds-assistive-text">error</span>
            <lightning-icon icon-name={iconName} alternative-text={type}></lightning-icon>
            <div class="slds-notify__content">
                <h2>{title}</h2>
                <p>{message}</p>
            </div>
            <div class="slds-notify__close">
                <lightning-button-icon icon-name="utility:close" alternative-text="Close"></lightning-button-icon>
            </div>
        </div>
    </div>
</div>

JavaScript I am not sure how to include @API invoke here. I keep getting a syntax error.

import { LightningElement, api, wire } from 'lwc';
import someMethod from '@salesforce/apex/clsSubmitToOrderLWC.ValidateQuoteForApproval';


export default class lwvSubmitToOrder extends LightningElement {
@api invoke() {
    //Call Method that returns the Message if something is not filled out. 
    //Else Return Submitted
    @wire(someMethod, {idProduct:'$recordId' })

    callSomeMethod({error, data}) {
        if (data) {
            // process results
        } else if (error) {
// this.template.query() seems not valid for LWC use this.template.querySelector as below            
//this.template.query('c-toast').show(error.message || error.body.message, 'error');
this.template.querySelector('c-toast').show(error.message || error.body.message, 'error');

        }
    }
}
}

APEX

public with sharing class clsSubmitToOrderLWC {

@AuraEnabled(cacheable=true)
public static SBQQ__Quote__c soQuote(Id idQuote) {
    
    return [Select Id, SBQQ__LineItemCount__c, Order_Entry_Admin__c, RecordType.DeveloperName
    From SBQQ__Quote__c 
         Where Id = : idQuote];

}


@AuraEnabled
public static String ValidateQuoteForApproval(SBQQ__Quote__c soQuote) {
boolean blnError = False;
String strErrorMessage = '';
  
    If(soQuote.RecordType.DeveloperName == 'Official_Sales_Quote'){
        soQuote.Sales_Order__c = True;
    }

    If(soQuote.SBQQ__LineItemCount__c == 0){
       strErrorMessage = strErrorMessage +  'Wait a Second! This Particular Quote has no Quote Line items' + '<br>';
       blnError = True;    

    }
    If(soQuote.Order_Entry_Admin__c == null){
       strErrorMessage = strErrorMessage +  'This Quote does not have Order Entry Admin Selected! ' + '<br>';
       blnError = True;    

    }

    If(blnError == True){
          Return strErrorMessage;
    }Else{
        Update soQuote;
        Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
        req1.setComments('');
        req1.setObjectId(soQuote.id);
        Approval.ProcessResult result = Approval.process(req1);
              
        strErrorMessage = 'No Validation Message Submitted for Approval';
        Return strErrorMessage;  
    }
}
}
2
  • is this a screen action or just an action? invoke is only available for headless actions (no screen). What is the syntax error message you receive? Jun 29 at 19:29
  • Yes I want a headless action like this: forcetrails.com/2021/05/… - the outcome is to display strErrorMessage on Screen
    – CodeMonger
    Jun 29 at 19:57
0

I figure it out..

You cant use @API Invoke and @Wire together.

@api invoke() {
@wire(someMethod, {idProduct:'$recordId' })

you have to write it like this:

@api invoke() {

someMethod, {idProduct:'$recordId' })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.