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
MAITREYEE DINGAREMAITREYEE DINGARE 

Variable does not exist: Apex @AuraEnabled method error

Hello all,

I am very new to APEX, and I am trying to match the Account Id of one custom object to another customer custom object. I am using this code into Lightning Component, so I have used @AuraEnabled. I am getting variable does not exist error for variable 'besuchsbericht'. Here is my code snippet:
public class PriceBookEntriesFromAccount {
    
    @AuraEnabled
    public Id currentBB{get; set;}
    
    public PriceBookEntriesFromAccount(ApexPages.StandardController controller) 
    {
        currentBB = Apexpages.currentpage().getParameters().get('id');
    }
    
    @AuraEnabled
    public list<Besuchsbericht__c> besuchsbericht = [SELECT Unternehmen__r.Name FROM Besuchsbericht__c WHERE Id =:currentBB];
   
    @AuraEnabled
    public static List<BB_Produkt__c> getPriceBookEntries() {
        List<BB_Produkt__c> bb = 
            [SELECT Name, Id, Produkt__r.Name, Verkostung__c, Kaufinteresse__c, Unternehmen__r.Name 
             FROM BB_Produkt__c 
             WHERE Unternehmen__r.Name = :besuchsbericht];
        //Add isAccessible() check
        return bb;
    }
}
My apologies for some variable names in the German language.
Any help would be appreciated. 

Thank you!
Maitreyee Dingare
Best Answer chosen by MAITREYEE DINGARE
Ashish Singh SFDCAshish Singh SFDC
Hi Maitreyee,

This code is valid for Visualforce:
public PriceBookEntriesFromAccount(ApexPages.StandardController controller) 
    {
        currentBB = Apexpages.currentpage().getParameters().get('id');
    }

Instead you need to implement : forceRecordId in Aura Cmp. This will get the value from the URL and then you need to supply this id from JS Action call to server.

Here is the the example:  https://salesforce.stackexchange.com/questions/187005/how-send-the-parameter-recordid-from-lightning-component-to-apex-controller

Thanks,
Ashish Singh.

All Answers

Ashish Singh SFDCAshish Singh SFDC
Hi Maitreyee,

This code is valid for Visualforce:
public PriceBookEntriesFromAccount(ApexPages.StandardController controller) 
    {
        currentBB = Apexpages.currentpage().getParameters().get('id');
    }

Instead you need to implement : forceRecordId in Aura Cmp. This will get the value from the URL and then you need to supply this id from JS Action call to server.

Here is the the example:  https://salesforce.stackexchange.com/questions/187005/how-send-the-parameter-recordid-from-lightning-component-to-apex-controller

Thanks,
Ashish Singh.
This was selected as the best answer
Ashish Singh SFDCAshish Singh SFDC

<aura:component controller="MyController" implements="force:hasRecordId" access="global" >

Record Id is here : "{!v.recordId}"

    <aura:handler name="init" action="{!c.doInit}" value="{!this}" access="global" />
</aura:component>
 
doInit : function(component, event, helper) {

    var action = component.get("c.setViewStat");    
    var recordId = component.get("v.recordId");

    console.log(artId);

    action.setParams({
        "recordId ":recordId 
    });
    // Queue this action to send to the server
    $A.enqueueAction(action);
}

 
MAITREYEE DINGAREMAITREYEE DINGARE
Thanks Ashish. The link you shared solved the issue.