Tuesday, June 16, 2020

Apex trigger to Store File type Attachment in Document folder Whenever Article is updated

Trigger Create_Doc on Knowledge__kav (After insert) {
    list<id> ids = new list<id>();
    For(Knowledge__kav k : trigger.new)
    {
        ids.add (k.Id);
    }
    list<Knowledge__kav> recs = [select  Upload__Name__s, Upload__ContentType__s,     Upload__Length__s, Upload__Body__s from Knowledge__kav where id =: ids];
    for(Knowledge__kav k1 : recs)
    {
        Document doc = new Document();
        doc.Name = k1.Upload__Name__s;
        doc.FolderId = '00l2v000002hABpAAM';  // Document folder id
        doc.Body = k1.Upload__Body__s;
        doc.ContentType = k1.Upload__ContentType__s;
        doc.Type = k1.Upload__ContentType__s;      

        insert doc;
    
    }
}


  As I've created one article name "upload file3" with file type attachment "test.txt"



After Update this article file type attachment "text.txt" is inserted in document with folder public images





Thanks,
Lovesalesforceyes.





No comments:

Post a Comment

Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...