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
ram123ram123 

global controller - apexpages.currentpage() returns null

I have a global with sharing controller which I'm using in VF page which uses JS Remoting. When I call ApexPages.Currentpage() or ApexPages.Currentpage().getParameters(), I'm getting null exception, anybody facing this issue ? is it a limitaion ?

 

Thanks

Ram

 

nagalakshminagalakshmi

Hi ram,

 

where you can declare this in constructor? or directly in method?

 

Thanks

ram123ram123

Its a global class with sharing and a global constructor,

 

following format:

 

//

global with sharing class dashboard{

 

 

global dashboard(){

 

}

 

@RemoteAction
  global static List<Dashboard.Chart> doCalculations(){

     //i'm callling apexpages.current page here, it returns null.

 

  }

global class chart{

 

}

 

}

 

 

 

I think visualforce might assume since its a remot action method, this kind of web services method, no page associated with it, may be thats why I'm getting null.

 

 

Thanks

Ram

 

RogerFTRogerFT

Did you manage to resolve this, Ram?  I'm attempting to retrieve current user's ip address in a @RemoteAction method.  For the same reason you stated ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP'); returns null.

 

I have an idea to hack it by storing the user's ip address in a hidden field when they first arrive on the page.  I'd grab the ip address and pass it along in the remote call, but that isn't very elegant.

 

Is there no way to access the user's request headers/cookies in a remote call?

 

Thanks

ram123ram123

When you say @remoteaction, I think visualforce assumes your request is async, so if its async there is no pagereference context available for that request. this is my reasoning. you might have to pass the params explicity to the method from client (javascript).

 

Thanks

ram

 

Amey PriolkarAmey Priolkar
I think you can't do it via Apex. But there's a workaround for it:
Pass the parameters in script on the page using {!$currentpage.parameters.parameter_name}
You will be able to again concatenate and use it in Apex though.