Tuesday 31 May 2016

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 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';
            }
        }
    }
}

No comments:

Post a Comment

Batch Apex

1. What are transaction limits in apex? Total number of SOQL queries issued1 - 100 Total number of records retrieved by SOQL queries - 50...