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
Prateek Kumar 11Prateek Kumar 11 

Variable does not exist in Extension Controller

Below is the code sample I'm trying to put in a controller extension class. However, I'm getting "variable does not exist: opp.id" error at line 13. The actual code makes a http callout to an external service. I'm trying to write code to make a javascript remoting call on click of a button from a VF page. Could you please help
 
public class TestPageEx {
    private final Opportunity opp;
    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    public TestPageEx(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
    }
    
    @RemoteAction
    public static String aaExample(String s)
    {
        Attachment att=   [Select Id,ParentId, Name,body,ContentType From Attachment where ParentId = :opp.Id limit 1];

}

}

Thanks.
@Karanraj@Karanraj
In Apex programming you can't access the non-static variable in the static method.
Only static variables are allowed to access within the static method.
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
public class TestPageEx 
{
    public static Opportunity opp;
    public TestPageEx(ApexPages.StandardController stdController) 
	{
        this.opp = (Opportunity)stdController.getRecord();
    }
    
    @RemoteAction
    public static String aaExample(String s)
    {
        Attachment att=   [Select Id,ParentId, Name,body,ContentType From Attachment where ParentId = :opp.Id limit 1];

	}

}
gbu.varungbu.varun
Try to use 
    public static Opportunity opp {get;set;}