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
kirankumarreddy punurukirankumarreddy punuru 

help me to solve this

I am writing a test class feed item trigger ,iam getting this error can anyone help me
my trigger is
error:System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ChatterPostTrigger: execution of BeforeInsert

caused by: System.QueryException: List has no rows for assignment to SObject

Trigger.ChatterPostTrigger: line 11, column 1: []


@isTest
Public with sharing class ChatterPostTriggerTest {
 static testmethod void testChatterPostTrigger(){ 
Profile pr = [Select Id from Profile where Name='Standard User'];
User u = new User();
        u.Username  ='kiranp@test.com';
        u.LastName  ='John jane';      
        u.Alias     = 'jjhan';
        u.CommunityNickname = 'jhane';    
        u.Email ='kumarp@test.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.ProfileId = pr.Id;
        insert u;
        
        // Inserting  feedItems list
        List<FeedItem> feedItems = new List<FeedItem>();
        FeedItem f = new FeedItem();
        f.Body = 'This is test class';
        f.ParentId = u.Id;
        f.ContentDescription = 'this is test class for feed item';
        f.ContentFileName ='test file';
        f.Title ='test class';
        f.Type = 'PollPost';
        feedItems.add(f);
        insert feedItems;
        
        //Collabaration Group Insertion
        List<CollaborationGroup> collabarationgroup = new List<CollaborationGroup>();
         CollaborationGroup   CG = new CollaborationGroup();
         CG.Description = 'This is Collabarationgroup' ;
         CG.Name ='MYGroup';
         
         collabarationgroup.add(CG);
         insert collabarationgroup;
         
         // Collabaration Group Member Insertion
          List<CollaborationGroupMember> cgm = new  List<CollaborationGroupMember>();
          CollaborationGroupMember CGMember = new CollaborationGroupMember();
          //CGMember.CollaborationGroupId = CollaborationGroup.Id;
         // CGMember.MemberId = CollaborationGroup.Id;
         CGMember.CollaborationRole ='Standard';
          cgm.add(CGMember);
          insert cgm;  
         
        }
        }
KaranrajKaranraj
Error is in the 'ChatterPostTrigger' trigger code in the line number 11. The error might be due to query is not returning the value, can you share the code here, it will be easy for us provide you the correct solution
souvik9086souvik9086
In ChatterPostTrigger at line no 11, there is a query which is not returning any value. Try to populate value in test class according to the query at line 11 so that it will return a record.