Iam creating dummy records for Topic and its assignment.Topic is creating successfully Topic assignment shows error

Below error:

Failed to assign topic to null. Please ensure you have permissions to assign topics for this record.

I have checked profile level,assign topic is enabled whats the issue here.

    Topic newTopic = new Topic(Name='newArticleTopic', 
    insert newTopic;

    Topic newTopic2 = [select Id from Topic where Id=:newTopic.Id];


    TopicAssignment newTopicAssignment = new TopicAssignment(TopicId=newTopic2.Id, NetworkId='0DB24000000TNlXGAW');
    insert newTopicAssignment;
  • Do you have Salesforce Communities is enabled in your organization.? – Tushar Sharma Feb 13 '18 at 9:23

Get rid of that NetworkId assignment. You don't really need to assign it in test class.


Once you remove it, the query will return the record.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy