1

I am trying to pick up the value of a visual text input and validate if it exists in the database, the problem is that it throws me the following error "Variable does not exist: searchDir"

I leave my code (summarized):

Controller extension:

public class Direccion {

  public string searchDir{get; set;}
  public ApexPages.StandardController controller {get; set;}

  public Direccion(ApexPages.StandardController controller) {
    this.controller = controller;
  }

  @RemoteAction
  public static void verificarDireccion() {
    Account[] registros = [ SELECT FiscalAddress__c, BillingAddress__c, ShippingAddress__c
                            FROM Account
                            WHERE Account.FiscalAddress__c =: searchDir
                            OR Account.BillingAddress__c =: searchDir
                            OR Account.ShippingAddress__c =: searchDir
                          ];
    if(registros.size() > 0) {

    }else{

    }
  }
}

Visualforce:

<apex:page standardController="Account" extensions="Direccion" id="page">

<apex:inputText id="FiscalAdress" value="{!searchDir}"/>
5

searchDir is an instance variable. It is bound to a specific instance of the class Direccion - here, the controller extension.

static methods, such as @RemoteAction JavaScript remoting actions, aren't bound to a specific instance and have no access to the instance variables of the Visualforce page's controller. As such, all state must be passed to the remote action as parameters.

You need to modify the signature of your @RemoteAction method to

public static void verificarDireccion(String searchDir) {

and alter your Visualforce page's call to the method correspondingly, to pass the current value of this state variable directly to the method.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.