Salesforce 之 Knowledge Object 之 mass update published article

 

最近為了一項關於 Knowledge 的任務感到傷腦筋,是關於要一次更新數萬篇 article 的任務。

背景說明

Salesforce 裡面的 Knowledge ,是一個特別的模組。有著特別的功能……以及一些特別的限制。隨便講幾個出來,背後可能都藏了無數人踩過的坑。(詳細內容可見文末之參考資料)

光看他的 object API name,既不像一般 custom object 一樣有著「__c」的後綴,也不像 standard object 一樣的乾淨俐落毫無後綴。而是帶著一個「__kav」的後綴。光這一點就獨步於全 org 了。

而此次我要做的 patch 任務,如果以其它 object 的概念來說,就是一次 update 數萬筆 record 而已。不管是要用 data loader,或是用 workbench,甚或是寫一支 Apex Code 去跑個 update,都不是什麼困難的事。

但對於 Knowledge 來說,可說是無比的麻煩。
因為已經 publish 的 article 是不容編輯的。

When an article is published, the PublishStatus field on the KnowledgeArticleVersion object is changed from “Draft” to Online. If an attempt is made to update a published article via API, a message will be received indicating that only Draft articles can be updated.
https://help.salesforce.com/s/articleView?id=000333316&type=1 )

若以手動更新 article 的方式來說,就是要做這些步驟

  1. Edit the article as a draft。先把已經 publish 的 article 弄成 draft 的狀態。
  2. Update the fields。把你要更新的值填入 article 上的欄位並 save。
  3. Publish the artilce。把你新編輯好的 article publish 出去,成為一個新的 Knowledge Article Version,以取代掉前一版的 article。

如果只是要更新三篇五篇 artcle,還可以接受用手動方式來完成。如果是十多篇,就覺得應該要用一些自動化的方式了,更何況是數萬篇……

解法

解法一:寫支 Python 程式,用打 API 的方式去做 unpublish、update、publish的動作。

解法二:用 flow 去跑 loop 來 create a new draft for each article
https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A83e7SAB

參考資料

Knowledge 說複雜也不複雜,這整篇 guide 讀一讀,應該也就差不多了。

Salesforce Knowledge Developer Guide
https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_objects_knowledge__kav.htm

留言

這個網誌中的熱門文章

ISC2 CC (Certified in Cybersecurity Certification) 考試心得

Salesforce證照考試心得 (Administrator and Advanced Administrator)