Update Account Billing in Shipping address?

on

|

views

and

comments

Apex Trigger Scenario

→ Apex Trigger 2

Develop an Apex Trigger so that every time when any account is created or updated then Set the Value of the Billing Address is to Shipping Address.

Shipping Address

  • ShippingStreet
  • ShippingCity
  • ShippingState
  • ShippingPostalCode
  • ShippingCountry

Billing Address

  • BillingStreet
  • BillingCity
  • BillingState
  • BillingPostalCode
  • BillingCountry

Hands on

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

Dispatcher Class

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

Handler Class

				
					// Handler Class calls helper class
public with sharing class AccountTriggerHandler {
    public Static void beforeInsert(ListaccountList){
        AccountTriggerHelper.helperBeforeInsertUpdate(accountList);
    }
    public Static void beforeUpdate(ListaccountList){
        AccountTriggerHelper.helperBeforeInsertUpdate(accountList);
    }
 }
				
			

Helper Class

				
					 // Helper class
public class AccountTriggerHelper {
    public Static void helperBeforeInsertUpdate(ListaccountList){
      for(Account acc : accountList){
        acc.ShippingStreet = acc.BillingStreet;
        acc.ShippingCity = acc.BillingCity;
        acc.ShippingState = acc.BillingState;
        acc.ShippingPostalCode = acc.BillingPostalCode;
        acc.ShippingCountry = acc.BillingCountry;
      }
    }
}
				
			

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