• Sam King 7
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am trying to publish an article in my test code yet even with the exact code copied from the salesforce documentation nothing will allow me to publish an article. I have been working on this for days now and am always getting stuck on this step. Everything works if I allow it to run on test articles yet that isn't what I want.
Main Class (I want to be able to publish the knowledge articles so the second for loop which includes draft articles isn't used.)
public class KnowledgeTopicUpdate {
    @InvocableMethod(label='Update the knowledge topics' description='Runs when you update a knowledge article and sets the topic based off of the Team.')
    public static void UpdateTopic(List<ID> Ids){
        List<TopicAssignment> TopicIDs = [select TopicId, NetworkID from topicassignment where EntityId = :Ids];
        List<Knowledge__kav> Knowledge1 = [select Id from knowledge__kav where team__c = :Ids and language = 'en_US' and publishstatus = 'online'];
        List<Knowledge__kav> Knowledge2 = [select Id from knowledge__kav where team__c = :Ids and language = 'en_US' and publishstatus = 'draft'];
            for(TopicAssignment TopicAssignment:TopicIDs){
                for(Knowledge__kav TotalKnowledge: Knowledge1){
                    TopicAssignment a = new TopicAssignment(TopicId=TopicAssignment.TopicId, EntityId=TotalKnowledge.Id, NetworkId=TopicAssignment.NetworkID);
                    insert a;
                }
            }
            for(TopicAssignment TopicAssignment:TopicIDs){
                for(Knowledge__kav TotalKnowledge: Knowledge2){
                    TopicAssignment a = new TopicAssignment(TopicId=TopicAssignment.TopicId, EntityId=TotalKnowledge.Id, NetworkId=TopicAssignment.NetworkID);
                    insert a;
                }
            }
    }
}
Test Class
@isTest(seeAllData=false) public class KnowledgeTopicUpdate_UT { //need a knowledge article and a team and a topic assignment and need to create a topic assignment for the knowledge article based off of the team. static testMethod void MakeArticle() { contact newContact = new contact(RecordTypeId = '0120Y0000008qLvQAI', LastName = 'test', AccountID = '0010Y0000054qWDQAY'); insert newContact; String contactId = newContact.Id; team__c newTeam = new team__c(Name = 'testTeam', Team_Manager__c = contactId); insert newTeam; String teamID = newTeam.Id; knowledge__kav newArticle = new knowledge__kav(Title='test',summary='xyz',urlname='xyz', team__c = teamID); topic newTopic = new topic(NetworkId = '0DB0Y000000CablWAC', name = 'test'); insert newTopic; string topicID = newTopic.Id; insert newArticle; String articleId = newArticle.Id; TopicAssignment Topicass = new TopicAssignment(TopicId = topicID, EntityId = teamID, NetworkId = '0DB0Y000000CablWAC'); insert Topicass; boolean archived = false; List<Id> Id = new List<Id>(new Map<Id, team__c>([select Id from team__c where id = :teamID limit 1]).keySet()); KbManagement.PublishingService.publishArticle(articleId, true); test.startTest(); KnowledgeTopicUpdate.UpdateTopic(Id); if([select count() from topicassignment where entityid = :articleId] == 1){ archived = true; } system.assertEquals(true, archived); test.stopTest(); } }

Error
System.InvalidParameterValueException: Invalid ID. Class.KbManagement.PublishingService.publishArticle: line 5, column 1
Class.KnowledgeTopicUpdate_UT.MakeArticle: line 21, column 1


Thanks in advance.

Steps
1. Created a Flow to create 3 WorkOrderLineItem record based on the conditions - Record Type and Pricebook should match the expected value.

First record:
User-added image
Second Record:
User-added image
Third Record:
User-added image
The flow triggers on creating a Work Order record with the expected Record Type and PriceBook but it fails to create the third record. The field I chose in the third record is the same as that in the second record. 
I get the following error message:
Error element Testing_New (FlowRecordCreate).
This error occurred when the flow tried to create records: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id. For details, see API Exceptions.


This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: CreateWorkOrderLineItems
Type: Autolaunched Flow
Version: 30
Status: Active
Flow Interview Details
Interview Label: CreateWorkOrderLineItems 14/02/2018 3:27 PM
Current User: Johnson Titus (005w0000006It4x)
Start time: 14/02/2018 3:27 PM
Duration: 0 seconds
How the Interview Started
Johnson Titus (005w0000006It4x) started the flow interview.
Some of this flow's variables were set when the interview started.
varWorkOrderId = 0WO2X000000019JWAQ
varAccountId = 00120000006GOmQAAW
varWorkOrderRecordType = 012w0000000kdo3AAA
RECORD QUERY: WorkOrderLookup
Find one WorkOrder record where:
Id Equals {!varWorkOrderId} (0WO2X000000019JWAQ)
Result
Successfully found record.
{!varAccountId} = 00120000006GOmQAAW
{!varPriceBook} = 01sw0000001yRHPAA2
{!varWorkOrderRecordType} = 012w0000000kdo3AAA
DECISION: RecordType
Executed this outcome: General_Upgrade
Outcome conditions: and
1. {!varWorkOrderRecordType} (012w0000000kdo3AAA) Equals 012w0000000kdo3AAA
Logic: All conditions must be true (AND)
DECISION: ClientOrSupport_1_1
Executed this outcome: Support_1_1
Outcome conditions: and
1. {!varPriceBook} (01sw0000001yRHPAA2) Equals 01sw0000001yRHPAA2
Logic: All conditions must be true (AND)
RECORD CREATE: BRMsClientSignOff
Create one WorkOrderLineItem record where:
PricebookEntryId = 01uw000000zlKySAAU
RecordTypeId = 012w0000000kdmHAAQ
StartDate = {!Flow.CurrentDateTime} (14/02/2018 3:27 PM)
Subject = BRM's Client Sign Off
Type__c = BRM's Client Sign Off
WorkOrderId = {!varWorkOrderId} (0WO2X000000019JWAQ)
Result
A record is ready to be created when the next Screen or Wait element is executed or when the interview finishes.
RECORD CREATE: UpgradeAttach1xto_AttachBI
Create one WorkOrderLineItem record where:
PricebookEntryId = 01uw000000zlKyQAAU
RecordTypeId = 012w0000000kdj8AAA
StartDate = {!Flow.CurrentDateTime} (14/02/2018 3:27 PM)
Subject = Upgrade Attaché 1x to Attaché BI
Type__c = Install
WorkOrderId = {!varWorkOrderId} (0WO2X000000019JWAQ)
Result
A record is ready to be created when the next Screen or Wait element is executed or when the interview finishes.
RECORD CREATE: Testing_New
Create one WorkOrderLineItem record where:
PricebookEntryId = 01uw000000zlKyQAAU
Result
Failed to create record.

Error Occurred: This error occurred when the flow tried to create records: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id. For details, see API Exceptions.


Salesforce Error ID: 106773568-45175 (164668177)
 

I am trying to publish an article in my test code yet even with the exact code copied from the salesforce documentation nothing will allow me to publish an article. I have been working on this for days now and am always getting stuck on this step. Everything works if I allow it to run on test articles yet that isn't what I want.
Main Class (I want to be able to publish the knowledge articles so the second for loop which includes draft articles isn't used.)
public class KnowledgeTopicUpdate {
    @InvocableMethod(label='Update the knowledge topics' description='Runs when you update a knowledge article and sets the topic based off of the Team.')
    public static void UpdateTopic(List<ID> Ids){
        List<TopicAssignment> TopicIDs = [select TopicId, NetworkID from topicassignment where EntityId = :Ids];
        List<Knowledge__kav> Knowledge1 = [select Id from knowledge__kav where team__c = :Ids and language = 'en_US' and publishstatus = 'online'];
        List<Knowledge__kav> Knowledge2 = [select Id from knowledge__kav where team__c = :Ids and language = 'en_US' and publishstatus = 'draft'];
            for(TopicAssignment TopicAssignment:TopicIDs){
                for(Knowledge__kav TotalKnowledge: Knowledge1){
                    TopicAssignment a = new TopicAssignment(TopicId=TopicAssignment.TopicId, EntityId=TotalKnowledge.Id, NetworkId=TopicAssignment.NetworkID);
                    insert a;
                }
            }
            for(TopicAssignment TopicAssignment:TopicIDs){
                for(Knowledge__kav TotalKnowledge: Knowledge2){
                    TopicAssignment a = new TopicAssignment(TopicId=TopicAssignment.TopicId, EntityId=TotalKnowledge.Id, NetworkId=TopicAssignment.NetworkID);
                    insert a;
                }
            }
    }
}
Test Class
@isTest(seeAllData=false) public class KnowledgeTopicUpdate_UT { //need a knowledge article and a team and a topic assignment and need to create a topic assignment for the knowledge article based off of the team. static testMethod void MakeArticle() { contact newContact = new contact(RecordTypeId = '0120Y0000008qLvQAI', LastName = 'test', AccountID = '0010Y0000054qWDQAY'); insert newContact; String contactId = newContact.Id; team__c newTeam = new team__c(Name = 'testTeam', Team_Manager__c = contactId); insert newTeam; String teamID = newTeam.Id; knowledge__kav newArticle = new knowledge__kav(Title='test',summary='xyz',urlname='xyz', team__c = teamID); topic newTopic = new topic(NetworkId = '0DB0Y000000CablWAC', name = 'test'); insert newTopic; string topicID = newTopic.Id; insert newArticle; String articleId = newArticle.Id; TopicAssignment Topicass = new TopicAssignment(TopicId = topicID, EntityId = teamID, NetworkId = '0DB0Y000000CablWAC'); insert Topicass; boolean archived = false; List<Id> Id = new List<Id>(new Map<Id, team__c>([select Id from team__c where id = :teamID limit 1]).keySet()); KbManagement.PublishingService.publishArticle(articleId, true); test.startTest(); KnowledgeTopicUpdate.UpdateTopic(Id); if([select count() from topicassignment where entityid = :articleId] == 1){ archived = true; } system.assertEquals(true, archived); test.stopTest(); } }

Error
System.InvalidParameterValueException: Invalid ID. Class.KbManagement.PublishingService.publishArticle: line 5, column 1
Class.KnowledgeTopicUpdate_UT.MakeArticle: line 21, column 1


Thanks in advance.