• Sara Rudraraju 5
  • 0 Points
  • Member since 2018

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1

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];
            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.