You need to sign in to do that
Don't have an account?
Tarun Kaushik 11
Unable to update validation status while archiving the article Type
Hi
I want update the validation status of article type as 'Archived' when a published article is aricivied amnually by standard button 'Archive' on article Type
Tried with apex- invoked method through process builder but when article is archiving it is not calling process builder.( I mean when user is archiving the published article manually,process is not taking it as update on an article type)
and we gonna do it with batch class- if archived article is edited by any user then it has two version of article one is draft state and other one is in archived state. So it is showing (common.apex.runtime.impl.ExecutionException: You can't perform this action. Be sure the action is valid for the current state of the article, and that you have permission to perform it)
Below is the @invocable method
@InvocableMethod
public static void updateassignedto(List<Technical_Q_A__kav> techarticlelist)
{
Map<String,string> techarticletypidmap = new Map<String,string>();
Map<String,string> techarticleiddatemap = new Map<String,string>();
set<string> Technicalqaidset = new set<string>();
list<Technical_Q_A__kav> technicalqalist = new list<Technical_Q_A__kav>();
map<string,Technical_Q_A__kav> masteridarticlemap = new map<string,Technical_Q_A__kav> ();
List<Id> articleIDs = new List<Id>();
List<String> articleNumbers = new List<String>();
List<Id> tobearchivearticleIDs = new List<Id>();
if(tqa.Publishstatus=='Archived'){
for(Technical_Q_A__kav tq: [SELECT Id, ArticleNumber, KnowledgeArticleId,masterversionid,ValidationStatus
FROM Technical_Q_A__kav
WHERE PublishStatus = 'Archived' AND Language = 'en_US' ]){
Technicalqaidset.add(tq.KnowledgeArticleId);
system.debug('tkset'+Technicalqaidset);
try{String articleId = tq.KnowledgeArticleId;
String masterid = KbManagement.PublishingService.editArchivedArticle(articleId);
masteridarticlemap.put(masterid,tq);
articleNumbers.add(tq.ArticleNumber);
}
catch(exception e){
}
}
system.debug('masteridtk'+masteridarticlemap);
List<Technical_Q_A__kav> articles = new List<Technical_Q_A__kav>();
for (Technical_Q_A__kav d : [SELECT Id, KnowledgeArticleId
FROM Technical_Q_A__kav
WHERE PublishStatus = 'draft' AND Language = 'en_US' AND KnowledgeArticleId IN :Technicalqaidset]) {
// perform your updates
d.validationstatus='Archived';
articleIDs.add(d.KnowledgeArticleId);
articles.add(d);
system.debug('tkupdatelist'+articles);
if(articles.size()>0)
update articles;
}
}
for (String articleId : articleIds) {
tobearchivearticleIDs.add(articleId);
KbManagement.PublishingService.publishArticle(articleId, true);
}
for (String aarticleId : tobearchivearticleIDs) {
Datetime scheduledDate = NULL;
KbManagement.PublishingService.archiveOnlineArticle(aarticleId, scheduledDate);
}
I want update the validation status of article type as 'Archived' when a published article is aricivied amnually by standard button 'Archive' on article Type
Tried with apex- invoked method through process builder but when article is archiving it is not calling process builder.( I mean when user is archiving the published article manually,process is not taking it as update on an article type)
and we gonna do it with batch class- if archived article is edited by any user then it has two version of article one is draft state and other one is in archived state. So it is showing (common.apex.runtime.impl.ExecutionException: You can't perform this action. Be sure the action is valid for the current state of the article, and that you have permission to perform it)
Below is the @invocable method
@InvocableMethod
public static void updateassignedto(List<Technical_Q_A__kav> techarticlelist)
{
Map<String,string> techarticletypidmap = new Map<String,string>();
Map<String,string> techarticleiddatemap = new Map<String,string>();
set<string> Technicalqaidset = new set<string>();
list<Technical_Q_A__kav> technicalqalist = new list<Technical_Q_A__kav>();
map<string,Technical_Q_A__kav> masteridarticlemap = new map<string,Technical_Q_A__kav> ();
List<Id> articleIDs = new List<Id>();
List<String> articleNumbers = new List<String>();
List<Id> tobearchivearticleIDs = new List<Id>();
if(tqa.Publishstatus=='Archived'){
for(Technical_Q_A__kav tq: [SELECT Id, ArticleNumber, KnowledgeArticleId,masterversionid,ValidationStatus
FROM Technical_Q_A__kav
WHERE PublishStatus = 'Archived' AND Language = 'en_US' ]){
Technicalqaidset.add(tq.KnowledgeArticleId);
system.debug('tkset'+Technicalqaidset);
try{String articleId = tq.KnowledgeArticleId;
String masterid = KbManagement.PublishingService.editArchivedArticle(articleId);
masteridarticlemap.put(masterid,tq);
articleNumbers.add(tq.ArticleNumber);
}
catch(exception e){
}
}
system.debug('masteridtk'+masteridarticlemap);
List<Technical_Q_A__kav> articles = new List<Technical_Q_A__kav>();
for (Technical_Q_A__kav d : [SELECT Id, KnowledgeArticleId
FROM Technical_Q_A__kav
WHERE PublishStatus = 'draft' AND Language = 'en_US' AND KnowledgeArticleId IN :Technicalqaidset]) {
// perform your updates
d.validationstatus='Archived';
articleIDs.add(d.KnowledgeArticleId);
articles.add(d);
system.debug('tkupdatelist'+articles);
if(articles.size()>0)
update articles;
}
}
for (String articleId : articleIds) {
tobearchivearticleIDs.add(articleId);
KbManagement.PublishingService.publishArticle(articleId, true);
}
for (String aarticleId : tobearchivearticleIDs) {
Datetime scheduledDate = NULL;
KbManagement.PublishingService.archiveOnlineArticle(aarticleId, scheduledDate);
}