Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.

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);

}

}

2 answers
  1. Jul 5, 2023, 5:38 PM
    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.
0/9000