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 

Can someone tell me what this error explains

System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, U#22e.bff (LastEditBy), cannot be null when revision is greater than 1: [LastEditById]

my test class for trigger is:
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
        
        // Insert the feeditem
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        //feed.ParentId = u.Id;
        feed.ContentDescription = 'this is test class for feed item';
        feed.Title ='test class';
        feed.Type = 'PollPost';
        feed.Revision =2;
        insert feed; 
    }
}
 
Abhishek BansalAbhishek Bansal
Hi,

Please update your test class from below code :
 
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
        
        // Insert the feeditem
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        //feed.ParentId = u.Id;
        feed.ContentDescription = 'this is test class for feed item';
        feed.Title ='test class';
        feed.Type = 'PollPost';
        feed.LastEditById = UserInfo.getUserId();
        feed.Revision =2;
        insert feed; 
    }
}

Let me know if you still have any issue.

Thanks,
Abhishek
Vishal Negandhi 16Vishal Negandhi 16
Just tried this out in developer console, you're passing feed.Revision=2. 
As per the message, if your revision is greater than 1, you also need to specify a value for the field "LastEditById" and "LastEditDate" (as a revision means a change has been applied and hence it asks for the person who last edited it and the date when it was edited.  

Few other observations
- if content not needed you might comment out feed.ContentDescription field. 
If you need it, then the feed.Type should be one of these: AdvancedTextPost, ContentPost, QuestionPost. 
- ParentId is a required field, you might want to add some value there too. 

Roughly, if you try the below code, you should be able to create the feeditem. 
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
        
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        feed.ParentId = Userinfo.getUserId(); // not sure what your parent id has to be
        feed.ContentDescription = 'this is test class for feed item';
        feed.Type = 'QuestionPost'; // added this because of the above line
        feed.Title ='test class';
        feed.Revision =2;
        feed.LastEditById = Userinfo.getUserId(); // this is required if revision > 1
        feed.LastEditDate = date.today();       // this is reired if revision > 1 
        insert feed; 
    }
}

Hope this helps. Happy coding!