• DisruptiveStartup
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    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 */
        
    }   
}

 

 

I have given the customer portal user rights to 2 custom objects (ParentObject and ChildObject).

 

Both objects have the "Customer Portal Enabled" checkbox checked.

All the necessary fields in field level security are ticked for the profile.

 

The page is as follows;

 

<apex:page standardController="ParentObject" >

 

        <apex:relatedList list="ChildObjects__r" />

</apex:page>

 

 

Viewing this page as system admin looks fine.

Viewing this page as a customer portal user returns the following error:

" 'ChildObjects__r' is not a valid child relationship name for entity ParentObject"

 

Does anyone have any ideas ?

Interested parties can send their details to DisruptiveStartUp@SeedLogic.co.uk

 

Recruiters need not make contact.

I noticed that my Visualforce page threw the following error when I tried to add a related list that was perfectly well defined in the object's setup but happened not to be in the Page Layout: 'SubContracts__r' is not a valid child relationship name for entity Licensing Contract

This appears to be an undocumented restriction on the use of <apex:relatedList> not to mention one that could potentially cause some nasty issues in a production environment should an admin update a page layout or create a new one after the orginal page is deployed. Likewise, if they create new recordtypes or recordtype/profile assignments. This restriction is not intuitive; one generally thinks of Visualforce as an alternative to a Page Layout, not as an extension that is bound to it and inherents its content restrictions. Additionally, for developers who have over-ridden all page-layouts for an object with VF pages, it is counter-intuitive to have to edit a Page Layout that is not in use simply to include the list in their VF pages.

Could someone respond back with some clearer details on how this actually works? Does Visualforce simply require that one page layout include the related list or does it require the page layout for the given record type include it. Wouldn't it be more robust to simply define the apex:related list to display based on user permissions rather than throw an error if the list is not found in the related page layout.


Message Edited by lnryan on 12-16-2008 01:12 PM
  • December 16, 2008
  • Like
  • 0