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
sai teja 69sai teja 69 

@api recordId not giving record id of the current record lightning page edit action LWC?

@api recordId not giving record id of the current record lightning page edit action LWC
I have placed LWC component in auracomponent. I have overrided the edit button action with this aura component.
 
<aura:component implements="flexipage:availableForAllPageTypes,lightning:actionOverride,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
	<c:lMCaseNew  recordId="{!v.recordId}"/> // invoking lwc component
</aura:component>
lwc.js
import { LightningElement, track, wire, api } from 'lwc';
import getCaseDetails from '@salesforce/apex/caseController.getCaseDetails';


export default class LMCaseNew extends NavigationMixin(LightningElement) {
@api recordId;

@wire(getCaseDetails, { caseId: '$recordId' })caseRecordDetails({data}){
        if(data){
            alert("data"+data);
        
        }else{
            alert(1);
        }
    }
apex.cls
@AuraEnabled
    public static List<Case> getCaseDetails(String caseId){
        system.debug('record Id'+caseId);
        List<Case> cs = [select Id,Issue_Name__c from Case where Id =: caseId];
        return cs;
    }


It is giving alert(1);
 
Ankit RathorAnkit Rathor
Hi Sai Teja ,

Please try this code:

import { LightningElement, wire, api } from 'lwc';
import getCaseDetails from '@salesforce/apex/getCaseDetails.test';

export default class LMCaseNew extends LightningElement {
@api recordId;

@wire(getCaseDetails, { caseId: '$recordId' })caseRecordDetails({data,error}){
if(data){
alert("data"+data);

}else{
alert(1);
}
}
}

========================================================================================

public with sharing class getCaseDetails {
@AuraEnabled(cacheable=true)
public static List<Case> test(String caseId){
system.debug('record Id'+caseId);
List<Case> cs = [select Id from Case where Id =: caseId];
return cs;
}
}

Note :: Apex methods that are to be cached must be marked as @AuraEnabled(cacheable=true)

Please let me know if you have any other query. If this solution is helpful then please mark it as Best Answer.

Thanks,
Ankit Rathor