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 start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

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