Quick HowTo - Salesforce Apex Trigger
Subsari Tech Consulting - Quick HowTo Apex Trigger

Quick HowTo - Salesforce Apex Trigger

Do you know how easy it is to create custom trigger actions on your Salesforce objects? If you don't, scroll down through our step-by-step screenshots.

Overview

In this post we show you how to use a checkbox to run an Apex Trigger that clears all the values of a list of object properties. In this scenario, we are using the concept of "Feature Flags" being cleared by a checkbox that essentially mimics the behavior of a button.

Some Context

Apex triggers allow you to write custom object logic. Custom code helps you automate trivial tasks as well as complex business rules. Sometimes custom business logic should be developed using low-code Workflow Automation while sometimes its code through Apex Triggers.

Step 1 - Add New Custom Fields

Salesforce Account New Custom Field

Step 2 - Accept All Defaults

Salesforce New Custom Field Step 3
Salesforce New Custom Field Step 4

Step 3 - Update Page Layout

It helps to have a section dedicated to "trigger actions". This can serve as your section that contains checkboxes that behave like buttons.

Salesforce Page Layout Details

Step 4 - View Your Custom Flags (You'll use this as a reference)

Salesforce Fields and Relationships Page

Step 5 - Write Apex Code & Mark "Is Active"

trigger AccountTriggerActions on Account(before insert, before update) {    
    for(Account a : Trigger.New) {
        If(a.Action_ClearAllFeatures__c){
            // primary logic - disable account features
            a.Feature_AB_Testing__c   = false;
            a.Feature_AlphaTester__c  = false;
            a.Feature_DarkMode__c     = false;
            a.Feature_LoadBalancer__c = false;
            
            // reset trigger action checkbox value
            a.Action_ClearAllFeatures__c = false;
        }       
    }
}


Salesforce Custom Account Address Trigger

Step 6 - Test It Out

Things To Keep In Mind

This approach should only be used in appropriate use cases. You should never generalize and assume that you can resolve all automation using this approach.

Why Is Salesforce The #1 CRM?

Extensibility. This article is a perfect example showcasing how you can extend CRM functionalities and capabilities to meet even the most complex business scenarios while gracefully handling simple use cases.

Additional Info

Subsari Tech Consulting - Dallas TX

https://www.dhirubhai.net/company/subsari/about/

https://subsari.com/

Feedback

Please continue to send us your comments and thoughts.



要查看或添加评论,请登录

Joel Pagan的更多文章

  • Scripture Censorship ????????????

    Scripture Censorship ????????????

    And so it begins..

  • Ayudis.ai - A Game Changer

    Ayudis.ai - A Game Changer

    ?? Everyone talks about A.I.

  • MIT - CloudSMART Overview

    MIT - CloudSMART Overview

    ?? Problem: Organizations are overspending on cloud services. Gartner estimates over 94% of organizations overspending…

  • IT Strategy & Customer Success...

    IT Strategy & Customer Success...

    Are you still fire fighting your business applications? The root problem more than likely lies within your current…

  • How To Move 30 Thousand People

    How To Move 30 Thousand People

    Ever wondered what it takes to encourage 30 thousand people to take action? Here is how we did so last Friday night at…

社区洞察

其他会员也浏览了