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
David MatusowDavid Matusow 

Variable does not exist:

I am a very experienced developer and just ran into one that I just don't see.  I'm trying to set a boolean variable from a javascript side.  Here is the portion of the code:
// variables correlating to the checkboxes
	Boolean accountb, leadb, opportunityb;
            
	@RemoteAction
    public Null SetCategory(String category , Boolean setv) {
	
		if (category == 'account') {
			accountb = setv;
(the code goes on with other setttings and ends with a close bracket)
The error shows "Compile Error: Variable does not exist: accountb at line 14 column 13".  accountb is just above this.  What am I missing??
 
Best Answer chosen by David Matusow
Deepak Kumar 138Deepak Kumar 138
Note - Please mark this as Best Answer if it solves your query. it will help others.

All Answers

Deepak Kumar 138Deepak Kumar 138
I guess it should be global.
// variables correlating to the checkboxes
	global Boolean accountb, leadb, opportunityb;
            
	@RemoteAction
    global static Null SetCategory(String category , Boolean setv) {
	
		if (category == 'account') {
			accountb = setv;
Deepak Kumar 138Deepak Kumar 138
minor correction - 
// variables correlating to the checkboxes
	global static Boolean accountb, leadb, opportunityb;
            
	@RemoteAction
    global static Null SetCategory(String category , Boolean setv) {
	
		if (category == 'account') {
			accountb = setv;

 
David MatusowDavid Matusow
setting it to global worked, but WHY?
Deepak Kumar 138Deepak Kumar 138
Apex @RemoteAction methods must be static and either global or public. and you can access only static variable from a static method.

This would also work fine - 
 
// variables correlating to the checkboxes
	public static Boolean accountb, leadb, opportunityb; //it can be even private
            
	@RemoteAction
    public static Null SetCategory(String category , Boolean setv) {
	
		if (category == 'account') {
			accountb = setv;

 
Deepak Kumar 138Deepak Kumar 138
Note - Please mark this as Best Answer if it solves your query. it will help others.
This was selected as the best answer