[SalesForce] FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

I am having some trouble inserting a set of values into a custom object (Article_Feedback__c)in my unit test. Does anyone see anything wrong with the way this test was setup? I have tried fixes on similar posts such as rolling back the API version but I cant seem to get it to work.

@isTest(SeeAllData=true)
public class ArticleFlagTest {
   static testMethod void addArticleFeedback(){

        FeedItem f;
        String parentId = 'kA0550000004CNPCA2';

        String q = 'SELECT KnowledgeArticleId, Title FROM KnowledgeArticleVersion WHERE PublishStatus = \'Online\' AND Language = \'en_US\' AND KnowledgeArticleId = \'kA0550000004CNPCA2\' LIMIT 1';


        group g = [SELECT Name,Id FROM Group WHERE Name = 'Knowledge Expert'];

        KnowledgeArticleVersion kav = (KnowledgeArticleVersion) Database.query(q);


        Article_Feedback__c afd = new Article_Feedback__c(
            Article_ID__c = parentId,
            /*Article_Number__c = kav.articleNumber,*/
            Article_Title__c = kav.title,
            Article_Link__c = 'https://login.salesforce.com/'+ kav.KnowledgeArticleId+ '?popup=true',
            Feedback_Status__c = 'Internal',
            OwnerID = g.Id

        );
        insert afd;       
    }

}

Best Answer

Groups cannot own records (only Users + Queues); Groups are for opening sharing.

This line is referencing a GroupId, not a UserId.

OwnerID = g.Id

Try substituting with your User.Id and see if it inserts or you.