function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav Pandey 5Gaurav Pandey 5 

Create Knowledge Article from Attachment using Apex

Hi All,

We have a requirment where we have an attachment and on certain condition we will have to create a Knowledge Article with the attachment.
Any leads would be quite helpful.

Thanks in advance!!
Edwin VijayEdwin Vijay
Good news is, it's doable and not so complex :)
  1.  Write a query on the Attchment object to fetch your desired ones.
  2. Insert into your knowledge article object (Note that this object is auto generated when you created a new article type and the object name ends with __kav) ... Get the exact API name by going into Setup -> Knowledge -> Knowledge Article Types
Insert into the __kav object and you have an article
Gaurav Pandey 5Gaurav Pandey 5
Hi Edwin,

Thanks for the response but i am not sure how can we create the attachment for the article from the attachment
i.e: The attachment should be attached to the Knowledge Article but the attachments for knowledge articles are not stored as attachments in the backend.
Edwin VijayEdwin Vijay
Hi Gaurav, You can create a custom field of type 'File' . You can then attach files the same way as attachments. However there is a max limit of 5 file fields you can add to article type
Gaurav Pandey 5Gaurav Pandey 5
Hi Edwin,

I tried so somehow i am not getting the way.
Are you having any sample code to acheive so that i refer it.

Thanks a lot !!!!!