Month: September 2020

Using Apex with Knowledge

 In continuation of my effort to make Lightning Knowledge easily understandable for all, today I am going to show how Salesforce Knowledge can be accessed using Apex. Salesforce Knowledge can have Apex Triggers and be accessible through Apex code. Actually, Salesforce provides some standard apex classes related to Knowledge Management that can be called for actions like publishing, editing as draft, archiving, and more.Before I start, I would recommend you going through my earlier posts -Understanding Salesforce Lightning Knowledge Data ModelHandy SOQL/SOSL Queries for KnowledgeWe can use the methods in KbManagement.PublishingService class to manage the lifecycle of an article. I am going to explain some of the few classes which developer needs mostly, but to know about all the methods, I highly recommend you going through the documentation here.Editing an Article as DraftWe can use the below method to edit an article as draft – String newId = KbManagement.PublishingService.editOnlineArticle(                    knowledgeArticleId,                     false               );Where the 1st input parameter is the KnowledgeArticleId (Note – This is not the Knowledge Record Id).2nd parameter is a Boolean value where false will not unpublish the already published articles and true will unpublish the already published article.This method will return the new draft master version ID of the article.Note – We need to keep this in mind that this method is not bulkified. So if...

Read More

Handy SOQL/SOSL Queries for Knowledge

 Happy Monday!! In my last post, I have explained the Data Model around Salesforce Lightning Knowledge. If you haven’t gone through that post, I highly recommend you going through the post “Understanding Salesforce Lightning Knowledge Data Model” as it is going to help you to understand the queries in this post.Let’s first create the article – “Hello World” and below are the different versions with different publishing status. Below article properties which I will be using the query -Article Number: 000001000Knowledge Article Id: kA03t00000063w2CAAFetching Latest Knowledge Article VersionSELECT Id,PublishStatus,Title FROM Knowledge__kav WHERE KnowledgeArticleId = ‘kA03t00000063w2CAA’ AND IsLatestVersion = TrueFetching Published Knowledge Article VersionSELECT Id,PublishStatus,Title FROM Knowledge__kav WHERE KnowledgeArticleId = ‘kA03t00000063w2CAA’ AND PublishStatus = ‘Online’Fetching Draft Knowledge Article VersionSELECT Id,PublishStatus,Title FROM Knowledge__kav WHERE KnowledgeArticleId = ‘kA03t00000063w2CAA’ AND PublishStatus = ‘Draft’Fetching Archived Knowledge Article VersionsSELECT Id,PublishStatus,Title FROM Knowledge__kav WHERE KnowledgeArticleId = ‘kA03t00000063w2CAA’ AND PublishStatus = ‘archived’ AND IsLatestVersion = FalseThis one is tricky, as to query Archived article versions, KnowledgeArticleId and IsLatestVersion = False and PublishStatus = archived should be mentioned.Note -Using bind variables with Apex SOQL Statements with KnowledgeArticleVersion is not allowed. So you need to use dynamic SOQL like below -final String ONLINE_ARTICLE = ‘Online’;final String myQuery = ‘SELECT Id FROM Knowledge__kav WHERE PublishStatus = :ONLINE_ARTICLE’;List<Knowledge__kav> allArtciles = Database.query(myQuery);Working with DATA CATEGORYWITH DATA CATEGORY is an optional clause in SOQL and it helps to identify articles linked with one or more...

Read More

Understand Salesforce Lightning Knowledge Data Model

While working with Lightning Knowledge, what I realized is that there is hardly any tutorial/post which explains the Knowledge Data Model in a very simple way. So I thought of writing my understanding with examples covering the part of the data model. I hope this will help you to understand the data model clearly and quickly.Understanding the data model is always very important while doing the development as it will help you to play with the objects and do configure/customization that is possible, basically getting the maximum benefit of the platform.To start with, the Knowledge Object Model is based on Abstract and Concrete objects. Core Abstract and Concrete ObjectsThe core abstract objects are – KnowledgeArticle and KnowledgeArticleVersion. The corresponding concrete versions are – Knowledge__ka and Knowledge__kav.Below is the data model from the Salesforce Developer Guide -Complete Data Model Relationship between Knowledge__ka and Knowledge__kavAs per the data model, the relationship between Knowledge__ka and Knowledge__kav is 1 to many. That is one Knowlegde__ka can have multiple Knowledge__kav. The link is happening through KnowledgeArticleId (remember KnowledgeArtcileId and Id are two different fields). So let’s check the example below.The “HelloWorld” article is having two versions – Now if I run the query against Knowledge__ka, I am getting one entry which provides me the KnowledgeArticleIdNow with the same KnowledgeArticleId, if I query Knowledge__kav, I will get one entry. Surprised?? Why only one entry where it should be...

Read More

Queueable Apex

 Earlier I wrote a blog post dedicated to Asynchronous processing in Salesforce. This time I will focus on Queueable Apex only.Queueable Apex is a more advanced version of future methods. It has all the functionalities of the future method along with the power of Batch Apex. So – Queueable Apex = Future Method + Batch ApexIt provides additional job chaining and allows for more complex data types.With Queueable Apex, developers will be able to submit jobs for asynchronous processing, like something future method can do as well. But the difference comes here -Flexibility in method parameters: With Queueable Apex, developers will be able to create classes that will allow member variables of non-primitive data types like sObjects or custom Apex types. Monitor the progress: Once the developer submits a job by executing the command System.enqueuJob, it provides an ID, which is basically a Job Id. With that Id, the developer can now query the progress either from Salesforce interface in the Apex Job page or by querying the AsyncApexJob table.Chaining jobs: Developer can now chain jobs i.e. starting a new queueable job from an already running queueable job.Batchable vs Future vs QueueableBatchable was the first one introduced by Salesforce for asynchronous heavy processing. It was “heavy” in terms of resource usage and also needs longer time to process/complete the work.To solve the problem with Batchable, Salesforce introduced the Future method. It...

Read More

New Admin Features From Winter 21 Release

In today’s post, I am going to share some of my favorite Admin features from Winter 21 release.SurveyWhile creating the survey, admins now have the option of saving the survey as a template. After creating the template, users can open it and make a copy from the top-right menu to create their own survey based on the template.Flow EnhancementsI have written a separate post covering only flow enhancements coming with Winter 21 release.Here is the post – Winter 21 Flow EnhancementsDynamic Form    With this release, admins now have the power to select the position of the fields in the page layout. As of today, this is only available to custom objects and Lightning App Builder.When admins will open the record details section from the Lightning page in App Builder, they will be presented with the option to Upgrade (as shown below). Selecting the upgrade option will provide the admins the option to create dynamic forms by positioning fields in different sections on the layout.Even admins can click on the “Analyze” button at the top right section which will provide them the option whether the customization is good from a performance standpoint.No More Ref IDs in Email-to-CaseRef IDs are not always our good friend when dealing with Email-to-Case, as people tend to delete, modify those ugly looking ids when sending emails/replies and that always causes problems with case routing.The good...

Read More

How to update “N” records in Flow

 If you are implementing business logic through Salesforce’s flow, you might need to loop through a list of records to do some manipulation. This is a very basic requirement. If you ever need to query records from Salesforce (let’s say all accounts where the billing country is India), it is very easy to do in SOQL and Get Records flow elements. But things will become a little tricky when the requirement says “Fetch first 5 accounts based on the created date where the billing country in India”. It is definitely very easy in SOQL with the limit statement, but in Get Records flow element, there is no way to (as of Winter’21 release) limit the record.To overcome this situation, we can implement the counter mechanism which will basically make sure that when the # of loop iteration is greater than 5 (because we just need the first 5 accounts), the flow will not perform any business logic.Here is the overall flow -Here as you can see for each loop iteration, we are incrementing the counter value by 1 and then checking whether the new value is greater than 5 or not. Based on that decision element, either we are updating the account’s rating i.e. performing business logic or ignoring the business logic execution. This flow solution is definitely making sure that only for the first 5 records the business logic...

Read More

Earlier Posts

  • 2024 (17)
  • 2023 (47)
  • 2022 (25)
  • 2021 (35)
  • 2020 (41)
  • 2019 (13)
  • 2018 (16)
  • 2017 (14)
  • 2016 (18)
  • 2015 (74)
  • 2014 (20)