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
hemantgarghemantgarg 

Not able to create Idea object in test class

I am trying to create an Idea object in test class as a customer portal user. but getting following error:

 

System.DmlException: Insert failed. First exception on row 0; first error: COMMUNITY_NOT_ACCESSIBLE, You do not have permission to access the community that this entity belongs to. You must be given permission to the community before you can access this entity.: [CommunityId]

 

I am using following apex code in test class:

 

 List<Community> listCommunity = [Select c.Name, c.IsActive, c.Id From Community c where IsActive=true and name=:TestClassUtility.PORTAL_COMMUNITY_NAME limit 1];
        
        System.runAs(portaluser){           
            Idea myIdea = new Idea(CommunityId = listCommunity.get(0).Id);
            myIdea.title = ' Test Idea';
            myIdea.body = ' test idea';
            insert myIdea;
            
            IdeaComment iComm = new IdeaComment(IdeaId = myIdea.Id);
            iComm.CommentBody = ' I like this idea';
            insert iComm;
       }

 

Thanks in advance for any help.

 

sebcossebcos

Hi,

I have the same problem, I have setup a customer portal and a community which is shown in the customer portal.

I have then created a custom portal user and after adding the idea tab I have successfully created an idea via the standard interface.

Moreover, I have created a simple visualforce page and controller:

 

 

<apex:page controller="IdeaController">
 <apex:form >
   <apex:commandLink value="post idea" action="{!postidea}"/>
 </apex:form>
</apex:page>

 

public class IdeaController{
    public Pagereference postIdea(){
    
            Idea myIdea = new Idea(CommunityId = '09aA0000000XdoL');
            myIdea.title = ' Test Idea';
            myIdea.body = ' test idea';
            insert myIdea;
            
            IdeaComment iComm = new IdeaComment(IdeaId = myIdea.Id);
            iComm.CommentBody = ' I like this idea';
            insert iComm;
            return null;
    
    }
}

 Please note i have hardcoded the ids, just for testing.

After, adding the page to the customer portal profile and accessing the portal as the portal user, I could post an idea, clicking on the link.

It looks like the test method does not allow what is otherwise possible, both with the standard UI and with visualforce/apex.

My two cents: I would log a case from your org and give access to salesforce support.

 

 

 

 

hemantgarghemantgarg

Thanks for the reply.

Is there any solution available for this. I tried to check the Field level security of Idea fields, surprisingly the field "CommunityId" is not available there in the list of Idea fields.

Sara Rudraraju 5Sara Rudraraju 5
Do you have a solution to this problem?
Thanks in Advance!