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 “Hello” on the Account Object (Data Type = text)
Trigger:
Trigger:
trigger HelloWorld on Account (before insert, before update) { list<account> accs = trigger.new; MyHelloWorld my = new MyHelloWorld();//creating instance of apex class my.addHelloWorld(accs);//creating method from the apex class }Class:
public class MyHelloWorld { public void addHelloWorld(List<account> accs){ for(Account a:accs){ If(a.Hello__c != 'World'){ a.Hello__c = 'World'; } } } }