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
Sujendran Sundarraj 8Sujendran Sundarraj 8 

Query in Extension Controller returns null with id from page

Hello All, 
I have a doubt, I have a standardcontroller for case object along with an extension controller. I am getting the id from the page and trying to query the case with the same id but the query is returning null. can you please help me to clear my doubt. Below is my code. 
public  class Testclass {
public  list<case> c {get; set;}
public id caseid {get; set;}
    public Testclass(ApexPages.StandardController controller) {
caseid = apexpages.currentpage().getparameters().get('id');
system.debug(caseid);

c = [select id, casenumber,subject, account.id from case where Id =: caseid];
system.debug(c);
    }


}

​​​​​​when I put a debug statement for caseid it is showing the id
but debug statement for c is returning null. 
 
Deepali KulshresthaDeepali Kulshrestha
Hi Sujendran,

The mistake is general You should use your standradcontroller instance to get the Id.

Do These Changes on Code:-->
public  class Testclass {
public  list<case> c {get; set;}
public id caseid {get; set;}
public Testclass(ApexPages.StandardController controller)
{
caseid = controller.getRecord().Id;
system.debug(caseid);

c=[select id, casenumber,subject, account.id from case where Id =: caseid];

}
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com