Play Games

Search This Blog

Wednesday, October 14, 2015

Error: Compile Error: Incompatible types since an instance of SObject is never an instance of opportunity

Generally we get this error when we are not doing type casting properly.
Recently I got this error when I am saving the below apex class.

Apex class :
public class OpportunityStatusChartController {
    public Opportunity opp;
 
    public OpportunityStatusChartController(ApexPages.StandardController std) {
        opp=(Opportunity) std.getRecord();
    }

}
Error:

Even though code is correct,I am getting this error.
Finally I understood that a class with name "Opportunity" is created in my instance
which is causing this error.
Solution: When ever you face this error,please check whether a class with that name
 is created and if a class exists,delete it