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
Hardik Baldania 4Hardik Baldania 4 

Error: Compile Error: Variable does not exist: dlrIdList at line 21 column 17

I'm trying to create a @RemoteAction with my javascript to work. But I'm getting this erorr all over again and again. I dont know where I'm going wrong in my codes. As this is my first time creating @RemoteAction class.

Here is my code which I created:

global with sharing class UdaanRemoter{

    public string cityname {get; set;}
    public list<Jaquar_Dealer_List__c> retdlr; 
    public Set<ID> dlrIdList;
    public UdaanRemoter()
    {
        dlrIdList = new Set<ID>();
    }
    @RemoteAction
    global static Jaquar_City_List__c getDealer(String cityname)
    {
         if(cityname != '')
        {
            Jaquar_City_List__c cityData= [SELECT Id, City__c, District__c, Pref_Dealer1__c, Pref_Dealer2_del__c,
                                                  Pref_Dealer3_del__c, State__c, Territory_Status__c 
                                                   FROM Jaquar_City_List__c WHERE City__c=: cityname];
            
            if(cityData.Pref_Dealer1__c != NULL)
            {
                dlrIdList.add((Id)cityData.Pref_Dealer1__c);
            }
            else if(cityData.Pref_Dealer2_del__c != NULL)
            {
                dlrIdList.add((Id)cityData.Pref_Dealer2_del__c);
            }
            else if(cityData.Pref_Dealer3_del__c != NULL)
            {
                dlrIdList.add((Id)cityData.Pref_Dealer3_del__c);
            }
            
            System.debug('Matching Dealer ID------------------------------->' + dlrIdList);   
            retdlr = [SELECT Id, Name, State__c, City__c, Dealer_Id__c, Email__c 
                                              FROM Jaquar_Dealer_List__c]; 
            dlrIdList.clear();
            System.debug('Matching Dealer Details------------------------------->' + retdlr);
        }
    
        } 
      
}

Can anyone help me on this. I would be really grateful. 

Thanks in Advance,
Hardik B.
Gokula KrishnanGokula Krishnan
Hi Hardik,

You need to declare the list(dlrIdList) variable inside Remote action method (o)r you need to declareing the variable as static.

Option 1 : public Static Set<ID> dlrIdList  = new Set<ID>();;
(or )
Option 2 :
 @RemoteAction
    global static Jaquar_City_List__c getDealer(String cityname)
    {
        Set<ID> dlrIdList  = new Set<ID>();

Reference : https://developer.salesforce.com/forums/?id=906F0000000B1IMIA0

if it helps you, please mark is as best answer, so it will be helpful for other developers.

Thanks,
Hardik Baldania 4Hardik Baldania 4
Hello, 

Visualforce Remoting Exception: line 18, column 1: List has more than 1 row for assignment to SObject Class.UdaanRemoter.getDealer: line 18, column 1

I have created the apex class and VF page which i used it as a RemoteAction to work with our existing code in JavaScript. I code is working working in VF page as expected but there is issue when i use RemoteAction on our existing plaform and the error again n again keeps on showing up. I don't know how to get it resolved. I'm sharing the Screenshot of the actual error and my apex code and the VF Pages as well.

Apex Code----------------------------------------


//Get the Dealer List based on the City
global with sharing class UdaanRemoter{

    public string cityname {get; set;}
    
    public UdaanRemoter()
    {
       
    }
    @RemoteAction
    global static List<Jaquar_Dealer_List__c> getDealer(String cityname)
    {
    Set<ID> dlrIdList  = new Set<ID>();
    list<Jaquar_Dealer_List__c> retdlr = new list<Jaquar_Dealer_List__c>();
    
         if(cityname != '')
        {
            Jaquar_City_List__c cityData= [SELECT Id, City__c, District__c, Pref_Dealer1__c, Pref_Dealer2_del__c,
                                                  Pref_Dealer3_del__c, State__c, Territory_Status__c 
                                                   FROM Jaquar_City_List__c WHERE City__c=: cityname];
            
            if(cityData.Pref_Dealer1__c != NULL)
            {
                dlrIdList.add((Id)cityData.Pref_Dealer1__c);
            }
            else if(cityData.Pref_Dealer2_del__c != NULL)
            {
                dlrIdList.add((Id)cityData.Pref_Dealer2_del__c);
            }
            else if(cityData.Pref_Dealer3_del__c != NULL)
            {
                dlrIdList.add((Id)cityData.Pref_Dealer3_del__c);
            }
            
            System.debug('Matching Dealer ID------------------------------->' + dlrIdList);   
            retdlr = [SELECT Id, Name, State__c, City__c, Dealer_Id__c, Email__c 
                                              FROM Jaquar_Dealer_List__c]; 
            dlrIdList.clear();
            
        }
        return retdlr;
        
        }      
}

VF Page -----------------------------------------------

<apex:page sidebar="false" showHeader="false" controller="UdaanRemoter">
    
  <head>
    <meta charset="UTF-8" /> 
    <title>Jaguar</title>
     
      <base href="{!URLFOR('/resource/1507619425000/')}" target="_blank" />
     
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/bootstrap.min.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/jquery-ui.min.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/custom.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/main_jaguar.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/font-awesome.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/jquery-ui.structure.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/animate.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/slick.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/slick-theme.css')}" />
      <apex:stylesheet value="https://flatlogic.github.io/awesome-bootstrap-checkbox/bower_components/Font-Awesome/css/font-awesome.css" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/build.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/react-input-range.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/react-select.min.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/drawer.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/preview.css')}" />
      <apex:stylesheet value="{!URLFOR($Resource.css, 'css/smk-accordion.css')}" />
      
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/rangeslider.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/jquery.min.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/bootstrap.min.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/jquery-ui.min.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/custom_functions.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/slick.min.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/drawer.min.js')}" />
      <apex:includeScript value="{!URLFOR($Resource.js, 'js/smk-accordion.min.js')}" />
   
  </head>
    
    <div id= "app">   </div>
    <script src="https://61960e2b.ngrok.io/bundle.js"> </script>
   
    
</apex:page>

User-added image

My Actual problem is Whenever I try to insert a Letter for City it should return the List of City starting with that letter but instead it shows this error. I dont know what's wrong with my code. Someone please help me.

Thanks in advance,
Hardik B.
Gokula KrishnanGokula Krishnan
Hi Hardik,

Try this,
 
if(cityname != '')
        {
            For(Jaquar_City_List__c cityData : [SELECT Id, City__c, District__c, Pref_Dealer1__c, Pref_Dealer2_del__c,
                                                  Pref_Dealer3_del__c, State__c, Territory_Status__c 
                                                   FROM Jaquar_City_List__c WHERE City__c=: cityname]){
            
				if(cityData.Pref_Dealer1__c != NULL)
				{
					dlrIdList.add((Id)cityData.Pref_Dealer1__c);
				}
				else if(cityData.Pref_Dealer2_del__c != NULL)
				{
					dlrIdList.add((Id)cityData.Pref_Dealer2_del__c);
				}
				else if(cityData.Pref_Dealer3_del__c != NULL)
				{
					dlrIdList.add((Id)cityData.Pref_Dealer3_del__c);
				}
            }
            System.debug('Matching Dealer ID------------------------------->' + dlrIdList);   
            retdlr = [SELECT Id, Name, State__c, City__c, Dealer_Id__c, Email__c 
                                              FROM Jaquar_Dealer_List__c WHERE Id =: dlrIdList]; // Added where condition to get specific city records
            dlrIdList.clear();
            
        }
        return retdlr;

Thanks,