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
Neil KimNeil Kim 

Controller] Using static variable with Remote action

Hi all!
I hava a controller having Remote action and normal function called by actionfunction.
In my VF, I call actionfunction first, and during this action, I save some value to static variable in Controller.
After then, Call remoteaction from VF and want to use the static variable, but it returns null.

I will show you my code
global class TestExtension {

    static String oId{get; set;}

   public PageReference setoId(){ // called first
        // some action
        Oid = something
        System.debug('oId : ' + Oid); // It shows me value as expected

        return null;
    }

    @RemoteAction        
    global static String bookingInsert(String context){
        System.debug('id : ' + oId); // it shows me null
        return oId;
   }
}

Any advise for resolving this problem?

Thanks!
 
Raj VakatiRaj Vakati
try this
 
global class TestExtension {

   public  static String oId{get; set;}
	
	public TestExtension(){
		  Oid = something
        System.debug('oId : ' + Oid); 
	}

   public PageReference setoId(){ // called first
        // some action
        Oid = something
        System.debug('oId : ' + Oid); // It shows me value as expected

        return null;
    }

    @RemoteAction        
    global static String bookingInsert(String context){
        System.debug('id : ' + oId); // it shows me null
        return oId;
   }
}

 
Neil KimNeil Kim
I cannot understand your guide. I cannot assign value to oId because source data for generating oId is not prepared at the constructor loading timing. Controller receive from VF/user for finding adequate oId.
Neil KimNeil Kim
I couldn't resolve this issue yet.
I find workaround that deliver Oid when BookingInsert call.

So, if you know the reason why it happens, please answer the question.
It will be helpful all including me.