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
SS KarthickSS Karthick 

Get the query string value in Remote Action Method

Hi folks,
       Can anyone tell me how to get the value of query string in Remote Method?
My code as follows
@RemoteAction
    global static Contact getContact() {
        String CID=ApexPages.currentPage().getParameters().get('id');
       
        String ContactId=CID.trim();
        
        contact c= [SELECT Id, FirstName, LastName,Phone FROM Contact WHERE Id= :ContactId];
        return c;
    }

I get the following error message while running the above code
attempt to de reference a null object


How can I fix this error?



Thanks in advance
Karthick
Best Answer chosen by SS Karthick
RishavRishav
Hii,
      you can't get the querystring parameter inside the @RemoteAction  method  because remoteaction method is stateless.. But if you want to operate on a specific id then you can pass the       id as a paramter from javascript and later receive this in function parameter.
   For reference you can use this link:
  http://salesforce.stackexchange.com/questions/11215/do-remoteaction-methods-have-access-to-page-parameters

 Thanks