5

I'm trying to pass recordId from LWC to APEX class to sumbit my record for the approval. However it gives me an error. My js:

import { LightningElement, track, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import SubmitRequestToCloseCommitment from '@salesforce/apex/LWCMethods.SubmitRequestToCloseCommitment';

export default class LWCCloseCommitment extends LightningElement {
  @api recordId;

  @wire(getRecord, { recordId: '$recordId', fields })
  Commitment__c;

  //Some criteria & modal processing

  updateCommitment() {
    // Some code how to update the record
    //Submit for approval - APEX imperative
    SubmitRequestToCloseCommitment({ ComID: this.recordId })
  }
}

APEX Class

public with sharing class LWCMethods {
  @AuraEnabled(cacheable=true)
  public static void SubmitRequestToCloseCommitment(string ComID){   
   System.debug('ID ' + ComID);
  //Some code to create an approval request
  }
}

The error I get is

[newValue cannot be undefined. Observable name: MapWithFilterOnSubscribeBehaviorSubject <= DistinctUntilChanged <= RootObservable: lds.Apex::LWCMethods:SubmitRequestToCloseCommitment:false:{"ComID":"a0l1w000002ci9LAAQ"}, newValue: undefined]

enter image description here

What am I missing? Thank you in advance!

2
  • afaik, any apex related to approvals causes DML, which is not allowed for cacheable methods
    – kurunve
    Dec 27, 2019 at 19:40
  • At this stage all Approval related code is commented, there is only a debug. Is there any other way how to force approval request from a LWC? Dec 27, 2019 at 19:47

1 Answer 1

4

I was able to reproduce and it got resolved when Apex method returned something as below:

public with sharing class LWCMethods {
  @AuraEnabled(cacheable=true)
  public static String SubmitRequestToCloseCommitment(string ComID){   
   System.debug('ID ' + ComID);
  //Some code to create an approval request
    return ComID;
  }
}

I don't have any reference to cite, but it seems that methods annotated with @AuraEnabled(cacheable=true) must return something.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .