0

I want to update data category selection from knowledge article's custom field.

enter image description here I have written a process builder and calling apex from there. but it is not updating data category selection But in debug logs i can see insertion is done. Below is the apex class:

@InvocableMethod
    public static void updatekMA1rticleType(List<Id> knowledgeid)
    {

        List<Knowledge__DataCategorySelection> kADCSLst = new List<Knowledge__DataCategorySelection>();
        List<Knowledge__kav> kArticle = [SELECT ID FROM Knowledge__kav  WHERE Id IN: knowledgeid];
       for(Knowledge__kav kak: kArticle)
        {
            Knowledge__DataCategorySelection kADCS = new Knowledge__DataCategorySelection();
            kADCS.ParentId = kak.Id;
            kADCS.DataCategoryGroupName = 'Geography';
            kADCS.DataCategoryName = 'India';
            kADCSLst.add(kADCS);
         }
          if(kADCSLst.size()>0)
            {

                insert(kADCSLst);
                system.debug('res**'+kADCSLst);

            }
     }

Can anyone help me?

5
  • @santanuBoral Can you help me on this?
    – SFDC
    Commented Jul 9, 2018 at 7:24
  • If I run the code from Developer Console, it is perfectly inserting data category into my one of the published article Commented Jul 9, 2018 at 9:34
  • @Santanu Boral: Thanks for reply..it is working fine for me too but when same code is called from process builder then it is not working.. I checked the logs it is inserting data but i think it is getting rolled back..I have written process builder on Knowledge object(__kav)..
    – SFDC
    Commented Jul 9, 2018 at 9:36
  • Is that correct version Id is getting passed to that method? can you post process picture? Commented Jul 9, 2018 at 9:40
  • @Santanu Boral: I added the picture of process builder. I am passing the [knowledge__kav.id] to the method. In debug logsi can see data categories selection is getting inserted but it is getting rolled back for some reason.
    – SFDC
    Commented Jul 9, 2018 at 10:21

1 Answer 1

0

I got the solution. I used @future annotation method called from @invocableMethod then it was working fine.

1
  • @ SFDC Can you please share where the @Future should be used from the abouve code? Commented Apr 20, 2020 at 9:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .