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
Bernardo Lira 1Bernardo Lira 1 

Pass record Id from page to LWC to Apex class not working

Hi all.

I have a problem trying to pass the (Account) recordId from the Lightning page to an LWC to an Apex class.

This is a line chart I plan to show in the Account detail page, but I am unable to pass the record Id from the page to LWC to Apex class. The LWC is used in a screen flow. In the Lightning page I pass the record Id.

JS:
import {LightningElement, wire, track, api} from 'lwc';
    import { getRecord } from 'lightning/uiRecordApi';
    import getEstosDatos from '@salesforce/apex/BC_PuntajeActor3valores.getEstosDatos';
    export default class BC_PuntajeActor3valores extends LightningElement {
        @api recordId;
        @track chartConfiguration;
        @track data;
        @wire(getEstosDatos , { recordId: "$recordId"})
        WireGetEstosDatos({error, data}) {
            if (error) {
                this.error = error;
          console.log('error => ' + JSON.stringify(error));
          this.chartConfiguration = undefined;
            } else if (data) {
                    let chartData = []; 
(...)

Apex class:
 
public class BC_PuntajeActor3valores {
    @AuraEnabled(cacheable=true)
    public static List<BC_Puntaje_semanal_actor__c> getEstosDatos(String actorId){
        return BC_PuntajeActor3valores.obtenerDatosGrafico(actorId);
    }
    
    @RemoteAction
    public static List<BC_Puntaje_semanal_actor__c> obtenerDatosRemotos(String actorId){
        return BC_PuntajeActor3valores.obtenerDatosGrafico(actorId);
    }
    
    public static List<BC_Puntaje_semanal_actor__c> obtenerDatosGrafico(String actorId){
        List<BC_Puntaje_semanal_actor__c> estosDatos = new List<BC_Puntaje_semanal_actor__c>();
        idActor=id.valueof(actorId);
        estosDatos = [select id, BC_Fecha__c, BC_Puntaje__c, BC_Orden__c from BC_Puntaje_semanal_actor__c where BC_Actor__c =: idActor order by BC_Orden__c];
        system.debug(estosDatos);
        return estosDatos;
    }
}


Note that if I change the 
@wire
line to
@wire(getEstosDatos , { recordId: "001H..."}) // this is an actual account record Id.
it does the trick (so I understand all the logic works, except that I'm unable to pass the record Id from the page to the LWC to the class).

Any help would be greatly appreciated!

Thx​​​​​​​
Arun Kumar 1141Arun Kumar 1141
Hi Bernardo Lira 1,

Try using this : 
@wire(getEstosDatos , { actorId: "$recordId" })  in place of  @wire(getEstosDatos , { recordId: "$recordId"}).
Hope this helps.

Thanks.
Bernardo Lira 1Bernardo Lira 1
Thank you Arun, but it didn't work. It didn't get to the class. I have some console.log written (removed them in the post to ease reading) and the JS didn't even enter the } else if (data) { code block (It's like "data" is false).

Look, I have these lines:
//@wire(getEstosDatos , { actorId: '001Hn00001tVArxIAG'})
	@wire(getEstosDatos , { actorId: "$recordId" })
When I swap the commented lines, like this:
@wire(getEstosDatos , { actorId: '001Hn00001tVArxIAG'})
	//@wire(getEstosDatos , { actorId: "$recordId" })
It works nicely (when the record Id is hardcoded).

Still in the dark here...