發表文章

目前顯示的是有「knowledge」標籤的文章

Knowledge 開發,再次踩坑再次記錄

  我還以為我跟 Knowledge 這個 module 已經算是混得很熟了……結果還是不小心為了一行 code ,debug de 了幾個小時…… 先講結論 如果想要 query archived 的 article,請記得加上 IsLatestVersion = False 的條件。 例如: list<Foo_Knowledge__kav> lstArchivedKB = [SELECT ID FROM Foo_Knowledge__kav WHERE KnowledgeArticleId =: article.KnowledgeArticleId and IsLatestVersion = False ]; 踩坑過程 我在 knowledge trigger 裡原本有一行 code: list<Foo_Knowledge__kav> lstPublishedKB = [SELECT ID FROM Foo_Knowledge__kav WHERE KnowledgeArticleId =: article.KnowledgeArticleId and (PublishStatus = ‘Online’ or PublishStatus = ‘Archived’)]; 用意是在一篇 article draft 被 created 的當下,去檢查這篇 article 是全新產生的亦或是從現有 article 衍生的。如果他是衍生的,那必定存在著至少一篇已經是 publish 或是 archived 的 record。 上面這行 code 也跑了幾個月了,UI上好像都運作正常。直到我這次試著使用 Python 打 API 的方式去 unpublish artilce,就出錯了……  unpublish API 示意: sf_api_call(‘/services/data/v51.0/knowledgeManagement/articleVersions/masterVersions/{}’.format(kavid), method=‘patch’, data={“publishStatus”: “draft”}) (相關紀錄請參見: Salesforce 之 Knowledge Object 之 mass update...

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 的方式來說,就是要做這些步驟 Edit the article as a draft。先把已經 publish 的 article 弄成 draft 的狀態。 Update the fields。把你要更新的值填入 article 上的欄位並 save。 Publish the artilce。把你新編輯好的 article publ...