Sunday 16 November 2014

Trigger on after insert and update example.

Trigger Fieldupfdate on Employee1__c (after insert, after update) {
  public static Boolean bool = true;
 if(bool){
 bool = false;
  List<Employee1__c> listemp = new  List<Employee1__c> ();
  Set<Id> setid = new Set<id>();
  for(Employee1__c empp:trigger.new){
   setid.add(empp.id);
  }
  List<Employee1__c> listem = [Select id,lastname__c from Employee1__c where id In : Setid];
  for(Employee1__c emp:listem){
   if(emp.LastName__c==null){
    emp.Lastname__c = 'Sampath';
    listemp.add(emp);
   }
  } update listemp;
}
}

1 comment:

  1. write scenarios and conditions with the triggers, it will be helpful to understand the trigger

    ReplyDelete