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
JJE_OLDJJE_OLD 

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

Hi,

 

I'm trying to create a controller extension for Campaigns and get the following error:


Compile Error: Incompatible types since an instance of SObject is never an instance of Campaign at line 7 column 32 

 

My extension class is the following:

public class CampaignControllerExtension {
    private ApexPages.standardController controller {get;set;}
    private Campaign currentTraining;
    
    public CampaignControllerExtension(ApexPages.StandardController stdController) {
        controller = stdController;
        this.currentTraining = (Campaign)stdController.getRecord();
    }
}

 Apparently there is an exception on Campaigns Sobject but I didn't find any clue on how to correct this.

 Any Ideas?

 

thanks,

Tejpal KumawatTejpal Kumawat

Hi try to this code..

 

public class CampaignControllerExtension {
    private ApexPages.standardController controller {get;set;}
    private Campaign currentTraining;
    
    public CampaignControllerExtension(ApexPages.StandardController stdController) {
        controller = stdController;
        this.currentTraining = (Campaign)stdController.getRecord();
    }
}

--------------------
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Thanks

 

 
JJE_OLDJJE_OLD

Sorry this was a mistyping, I corrected, but the problem is still there.

 

MayTheForceBeWithYouMayTheForceBeWithYou

Cloudy,

 

Check your Apex classes-my assumption is that you have an Apex class named 'Campaign' that is causing this issue. In this case, the apex logic you have written would be trying to cast the SObject to an instance of this custom Campaign class, rather than to an instance of the standard Campaign object as you intend. Hope that helps!