• ssDB
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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 */
        
    }   
}