Create an Apex Trigger to Update Industry Field?

on

|

views

and

comments

Table of Contents

Introduction to scenario

→ Apex Trigger 1
Develop an Apex Trigger so that every time any account is inserted then set the value of the Industry field to Education. Also, check if the Description is blank then set the value for the description field to “Account Description is blank

  1. Industry = Education
  2. Description = Account Description is blank if Description is null

Hands on

				
					//logic less trigger
trigger AccountTrigger on Account (before insert) {
    AccountTriggerDispatcher.dispatch(Trigger.operationType);
}
				
			

Dispatcher Class

				
					// dispatcher class
public class AccountTriggerDispatcher {
    public Static void dispatch(System.TriggerOperation operationType){
        switch on operationType{
            WHEN BEFORE_INSERT{
                AccountTriggerHandler.beforeInsert(trigger.new);
            }
        }
    }
 }
				
			

Handler Class

				
					//Handler class
public with sharing class AccountTriggerHandler {
  public Static void beforeInsert(ListaccountList){
    for(Account acc : accountList){
        if(acc.Industry== Null){
            acc.Industry = 'Education';
        }
        if(acc.Description == Null){
            acc.Description = 'Account Description is blank';
        }
    }
  }
}
				
			

Outcome

Resources

Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential