function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kallam salesforce1kallam salesforce1 

I am fetching recordId and passing to Apex method. But unable to get recordId in apex method.

import updateParentCase from '@salesforce/apex/UpdateMotherCase.updateParentCase';
export default class InitiateMotherCase extends LightningElement {
    @api recordId;
    handleClick(event){
       console.log('Get the record Id is'+this.recordId);
       
       updateParentCase({rid:'$recordId'}).then(result =>{
              console.log('Get details'+result);
           }).catch( error => {});
       
    }

 

Apex method>>>>>

@AuraEnabled(cacheable=true)
    public static void updateParentCase(String rid){
        try{
        System.debug('Get the case record Id details'+rid);
        list<Case> c = [SELECT id,CaseNumber,ParentId,Recently_Updated__c from case  where id =: rid AND ParentId != null];
        System.debug('Get the case details'+c);

}

}

 

SubratSubrat (Salesforce Developers) 
Hello ,

In your code, you are passing the value of recordId as a string literal 'recordId' instead of the actual variable value. To fix this, you need to remove the quotes around $recordId in the method call. Here's the corrected code:
import updateParentCase from '@salesforce/apex/UpdateMotherCase.updateParentCase';

export default class InitiateMotherCase extends LightningElement {
    @api recordId;

    handleClick(event) {
       console.log('Get the record Id is ' + this.recordId);
       
       updateParentCase({ rid: this.recordId })
           .then(result => {
              console.log('Get details: ' + result);
           })
           .catch(error => {
              console.error(error);
           });
    }
}
In the Apex method, the parameter type should be String, not void. Here's the corrected Apex method:
@AuraEnabled(cacheable = true)
public static void updateParentCase(String rid) {
    try {
        System.debug('Get the case record Id details: ' + rid);
        List<Case> c = [
            SELECT Id, CaseNumber, ParentId, Recently_Updated__c 
            FROM Case  
            WHERE Id = :rid AND ParentId != null
        ];
        System.debug('Get the case details: ' + c);
    } catch (Exception ex) {
        System.debug('An error occurred: ' + ex.getMessage());
    }
}

If this helps , please mark this as Best Answer.
Thank you.
kallam salesforce1kallam salesforce1

Hello Subrat,

I am trying with above code still unable to call apex method
User-added image