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);
}
}
Hello Subrat,
I am trying with above code still unable to call apex method
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:
If this helps , please mark this as Best Answer.Thank you.@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());
}
}