Monday, August 24, 2015

Explaining Trigger events

trigger updatefields on Account (before insert,before update,before delete,after insert,after update,after delete) {



List<account> ac=trigger.new;


List<account> ac1=trigger.old;
if(trigger.isbefore)
{
if(trigger.isinsert )
{


system.debug('333$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$am from insert###################new Data'+ac);

//system.debug('333$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$am from insert###################old Data'+ac1);
For(Account ac3:ac)
{
ac3.Name='Mr.' +ac3.Name;


}



}

if(trigger.isupdate)

{

system.debug('333$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$am from update###################new Data'+ac);
system.debug('333$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$am from update###################old Data'+ac1);


For(Account ac3:ac)
{
if(!ac3.Name.contains('Mr'))
{
ac3.Name='Mr.' +ac3.Name;
}

}


}

if(trigger.isdelete)
{
system.debug('333$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$am from delete');


}
}

if(trigger.isafter)
{
List<contact> con1=new List<contact>();
if(trigger.isinsert)
{
for(account ac6:trigger.new)
{

contact c1=new contact();


c1.lastname=ac6.Name;

con1.add(c1);



}
insert con1;
}
}










}

No comments:

Post a Comment