Category: Trigger

Kitchener Developer Group brings Virtual Learning in March 2021

 “Live as if you were to die tomorrow. Learn as if you were to live forever” by Mahatma Gandhi.Why not develop a passion for learning in March? Kitchener, CA Developer group is happy to bring three virtual sessions in March 2021. Below you will find all the details of the sessions. Please RSVP.Session 1Title:  Using Styling Hooks to Customize Your LWCDate & Time: Thursday, March 11, 2021, 2:00 PM ESTSpeaker: Kirupa Chinnathambi, Senior Director of Product/UX at SalesforceRSVP: HereSession 2Title:  Let’s Learn About Heroku and How to Integrate with SalesforceDate & Time: Thursday, March 18, 2021, 2:00 PM ESTSpeaker: Julian Duque, Lead Developer Advocate at SalesforceRSVP: HereSession 3Title:  Orchestrate ALL of your Salesforce Automation with the Trigger Action FrameworkDate & Time: Thursday March 25, 2021, 2:00 PM ESTSpeaker: Mitchell Spano, Application Engineer at GoogleRSVP: HereLooking forward to seeing you all at these awesome events.Note – Please check out this page to access the presentation and recording from all the previous events from Kitchener, CA Developer...

Read More

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

How to choose between Trigger and Lightning Process Builder

With the introduction of Lightning Process Builder, we can do many things which were kind of limitations of Workflows. Salesforce introduces Lightning Process Builder as successor of Workflow rules, thus allowing more config options through click and reducing amount of apex customization required. Process Builder supports all the features from Workflows with the exception of sending outbound message without apex code. I will not be surprised if Salesforce decides to decommission Workflow in near future.Previously there were few scenarios (listed below) which were not possible through workflow and we need to write Apex trigger to achieve those. Here are few of them -If we need to perform complex validationBefore/After logic for record insert/update/delete/undelete operation.Update/insert any objects or related records.Problem with workflow is we can’t update child records with workflow. Workflow supports only updation of parent record. So earlier we need to go for Trigger. But with the introduction of Process Builder, now we can update child records as well. Below is one case study -Case Study:It’s a library management system – Universal Library. Library is having many books. If the book is not available, user will send the request for the book. The moment book is available, all the request status will change from ‘Hold’ to ‘Ready to Pickup’. To achieve this below is the object model -Here Book and Book Request are connected through Master-Detail relationship. Previously to...

Read More

APEX TRIGGER DESIGN PATTERN

This post is part of the series – Design Pattern in ApexI know it was discussed number of times earlier about Apex Trigger Design Pattern. Below are few excellent posts -http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggershttp://www.embracingthecloud.com/2010/07/08/ASimpleTriggerTemplateForSalesforce.aspxI have learned a lot from the above two posts by Steve Andersen and Mike Leach.But the post by Abhinav Gupta really inspires me a lot and I am going to explain the pattern/template here with few use cases.The motivations for this design pattern are -Write Trigger with minimum codeFollow Salesforce Best Practice – One Trigger per objectFollow another Salesforce Best Practice – Move all code from Trigger to Apex Classes – Handler ClassesAbility to add and order multiple handlers for the same trigger event.Easy to maintain code base.Here is the Apex Trigger template – MyTriggers (Again inspired by Abhinav Gupta)Now using the above template, below is the account trigger handler – AccountTriggerHandlerAnd finally the trigger – AccountTriggerNow the trigger code is very neat and clean. At the same time all our operations against trigger events are moved to handler class.So now let’s consider few use cases -Use Case 1 -While inserting new accounts, if the Account Rating is marked as ‘Hot’, then mark those accounts as Active and make the Customer Priority as ‘Medium’.Implementation -To implement the above requirement, what we need to do is simply add the functionality in AccountTriggerHandler.AccountBeforeInsertHandler class. No changes in Apex trigger code is required.Here is the updated AccountTriggerHandlerUse...

Read More
Loading