Advertisement
f1lam3ntx0

create field on account and made chagnes

Aug 21st, 2022
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. Example 2:-
  2.  
  3. The following trigger updates the field called “Hello” by the value “World”whenever we are creating an account or updating an account record. Create the field called “Hello” on the Account Object (Data Type = Text)
  4.  
  5.  
  6. Trigger updateHello on Account (Before Insert , Before Update){
  7.   switch on Trigger.operationType{
  8.    when BEFORE_INSERT {
  9.     updateHelloHelper.updateHelloToWorld(Trigger.new);
  10.    }
  11.    when BEFORE_UPDATE{
  12.    updateHelloHelper.updateHelloToWorld(Trigger.new);
  13.    }
  14.   }
  15. }
  16.  
  17. public with sharing class updateHelloHelper {
  18.   public static void updateHelloToWorld(List<Account> accLst){
  19.   if(accLst != null){
  20.   List<account> accUpdate = new List<account>();
  21.   for(Account acc : accLst){
  22.   List<account> accQ = [select, id, name, hello from account];
  23.   acc.Hello = 'World';
  24.   accUpdate.add(acc);
  25.   }
  26.   INSERT accUpdate;
  27.   }
  28.   }
  29. }
Tags: Triggers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement