0

I am trying to pass the current id to my apex method but keep running into the following error.

message":"Value provided is invalid for action parameter 'caseID' of type 'Id'

My LWC is wrapped in a LC and used as a quick action

Apex:

@AuraEnabled(cacheable=true)
public static void getStatusCase(ID caseID){
    System.debug('here id: ' + caseID);
}

JS:

@api recordId;
handleClick(event) {
    updateStatusCase({ caseID: '$recordId'})
            .then(result => {
                window.console.log("updated");
            })
            .catch(error => {
                window.console.log("error: " + JSON.stringify(error));
            });   
}

I believe it is treating the recordid as a string and not ID.

2
  • @M guy in apex, the Id can be the type of Id or String. Where are you using your component? is it on record page?
    – Klecool
    Jun 8, 2020 at 14:57
  • It is wrapped in a LC and used as a quick action
    – M guy
    Jun 8, 2020 at 15:10

3 Answers 3

2

If your component is used as a quick action, you should wrap it in an aura component

<aura:component
    implements="flexipage:availableForAllPageTypes,force:hasRecordId"
    access="global">

    <c:aQuickActionLWC recordId="{!v.recordId}"></c:aQuickActionLWC>
</aura:component>

then in your LWC define a @api recordId propriety.

2
  • Perfect thank you
    – M guy
    Jun 8, 2020 at 15:24
  • You 're welcome!
    – Klecool
    Jun 8, 2020 at 15:26
4

Calling Apex imperatively (using a Promise) does not support dynamic variables, as far as I know. Only the Wire service. Since your use case cannot use a Wire (DML inside the Apex call), you should send the recordId in its standard form, not as a dynamic variable:

updateStatusCase({ caseID: this.recordId})
3
  • Its treating it as null in my apex method
    – M guy
    Jun 8, 2020 at 14:51
  • Make sure your component's meta XML file is set to associate the component with a specific record. Add this: <targets> <target>lightning__RecordPage</target> </targets>
    – EranV
    Jun 8, 2020 at 14:56
  • Yes lightning__RecordPage is there in my xml. Could the issue be because it is wrapped in a LC?
    – M guy
    Jun 8, 2020 at 15:19
0

How about passing the api variable in the following notation.

  @api recordId;
    handleClick(event) {
          updateStatusCase({ caseID: '$recordId'})
                .then(result => {
                    window.console.log("updated");
                })
                .catch(error => {
                    window.console.log("error: " + JSON.stringify(error));
                });   
    }

@AuraEnabled(cacheable=true)
public static void getStatusCase(String caseID){
    System.debug('here id: ' + caseID);
}
6
  • Its treating it as null in my apex method
    – M guy
    Jun 8, 2020 at 14:51
  • I have imported LightningElement and api. I thought @api recordId automatically got the id from the current record page. So all I needed to do is pass it to my apex method. Not sure why its null
    – M guy
    Jun 8, 2020 at 15:01
  • So use the same signature as Original Post updateStatusCase({ caseID: '$recordId'}) , In Apex Method declare the variable as a String
    – user40322
    Jun 8, 2020 at 15:01
  • I have. The only line I changed was that one to updateStatusCase({ caseID: this.recordId})
    – M guy
    Jun 8, 2020 at 15:02
  • Edited my answer
    – user40322
    Jun 8, 2020 at 15:05

You must log in to answer this question.

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