+ Start a Discussion
DisruptiveStartupDisruptiveStartup 

Testing Idea Extension controller

Does anybody know how to test an Idea Extension controller?

 

Salesforce have activated for me the IdeaStandardSetController and IdeaStandardController classes.

 

My code is as follows. The commented out text at the bottom of the test method are the options I have tried.

 

I have reviewed the documentation on Ideas controllers and I see the following;

Instantiation

An IdeaStandardController object cannot be instantiated. An instance can be obtained through a constructor of a custom extension controller when using the standard ideas controller.

 

As you can see from the below, I am using the IdeaStandardController and with that logic based on the above instantiation note I would have presumed my option two (in test method below) would be working.

 

The error message I get is as follow;

Compile Error: Constructor not defined: [ideaExtension].<Constructor>(ApexPages.StandardController) at line 51 column 29 

 

This corresponds to the first line in option 2.

 

public class ideaExtension{

    private final ApexPages.IdeaStandardController ideaController;
    public Idea idea {get;set;}
    public String commentBody{get;set;}
    public Boolean msgCommentPostingSuccess {get;set;}
    public Boolean msgCommentPostingError {get;set;}
    public String msgCommentPostingErrorSummary {get;set;}
    
    public ideaExtension(ApexPages.IdeaStandardController controller) {
        ideaController = (ApexPages.IdeaStandardController)controller;
        idea = (Idea)ideaController.getRecord();
        msgCommentPostingSuccess = false;
        msgCommentPostingError = false;
    }

    public PageReference insertComment(){
        IdeaComment comment = new IdeaComment();
        comment.CommentBody = commentBody;
        comment.IdeaId = idea.Id;
        try {  
            insert comment;
            msgCommentPostingSuccess = true;
        }
        catch(Exception ex) {
            // handle exception code here;
        }
        return null;  
     }
 
     /* TEST DATA METHODS */
     public static Idea createIdea(){
         Idea i = new Idea();
         i.Title = 'New Idea';
         i.body = 'My idea description';
         insert i;
         return i;
     }    
    static testMethod void testNewComment(){
        /* Create the test data */
        Idea testIdea = createIdea();
        
        /* Instatiate controller */

        // not working - Option 1
        //ApexPages.IdeaStandardController stdController = new ApexPages.IdeaStandardController(testIdea);
        //ideaExtension ext = new ideaExtension(stdController);
        
        // not working - Option 2
        //ApexPages.StandardController stdController = new ApexPages.StandardController(testIdea);
        //ideaExtension ext = new ideaExtension(stdController);

        // not working - Option 3
        //ideaExtension ext = new ideaExtension();
        
        /* Make assertions to validate logic */
        
    }   
}

 

 

ssDBssDB

Hi,

 

Were you able to get a solution to the problem? I am also stuck in similar situation and not able to get a solution.

 

Any help will be appreciated.

 

Sunny

viswadaviswada

Hi ,

 

   I have the same problem while writting test coverage for ideastadardController and ideaStandardset controller  , How can  we get  instance of  Ideastandardcontroller and ideaStandardsetcontroller. If you find any solution please  let me know how You resolved this issue, can  you show me the code   that is  really helpfulto me ,