You need to sign in to do that
Don't have an account?
Jotmenow
Too many dml statements knowledge
Hi, Iam trying to create a draft version of published articles using below code. It worked well for handful of records. I hv a scenario to update 3000 records. I receive TOO many DML statement errors.
Any fix here will help.
Used code:
for(FAQ__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
FROM FAQ__kav
WHERE PublishStatus = 'Online' AND Language = 'en_US']){
try{
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
}
catch(exception e){
//nothing to do here, draft existed
}
}
Any fix here will help.
Used code:
for(FAQ__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
FROM FAQ__kav
WHERE PublishStatus = 'Online' AND Language = 'en_US']){
try{
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
}
catch(exception e){
//nothing to do here, draft existed
}
}
Appreciate your response.
I tried creating a list only to find new error that knowledge articles object ending with __kav are not Sobjects.
So,list concept would not work.
I found a workaround which would work for 1-4000 records.
List of asyncronous code as below.
Increare offset by 150 each time and execute till closure.
for(standard__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
FROM standard__kav
WHERE PublishStatus = 'Online' AND Language = 'en_US' order by ArticleNumber limit 150 ){
try{
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
}
catch(exception e){
//nothing to do here, draft existed
}
}
for(standard__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
FROM standard__kav
WHERE PublishStatus = 'Online' AND Language = 'en_US' order by ArticleNumber limit 150 offset 150]){
try{
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
}
catch(exception e){
//nothing to do here, draft existed
}
}
All Answers
You need to bulkify your code to avoid this governor limit error.
Avoid writing DML statements inside the loops and use collections to perform DML operation on bulk records.
Thanks
Brahma
You can use Apex Batch to avoid the Error use below link for the reference:
http://salesforce.stackexchange.com/questions/9220/how-to-mass-archive-articles-in-apex
Let me know if this helps :)
Thanks!
Amit Singh
Appreciate your response.
I tried creating a list only to find new error that knowledge articles object ending with __kav are not Sobjects.
So,list concept would not work.
I found a workaround which would work for 1-4000 records.
List of asyncronous code as below.
Increare offset by 150 each time and execute till closure.
for(standard__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
FROM standard__kav
WHERE PublishStatus = 'Online' AND Language = 'en_US' order by ArticleNumber limit 150 ){
try{
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
}
catch(exception e){
//nothing to do here, draft existed
}
}
for(standard__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
FROM standard__kav
WHERE PublishStatus = 'Online' AND Language = 'en_US' order by ArticleNumber limit 150 offset 150]){
try{
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
}
catch(exception e){
//nothing to do here, draft existed
}
}