function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sunny.kapoor1306sunny.kapoor1306 

Trigger difference

Can anyone tell me the proper difference b/w trigger.old and trigger.new with eg's?

 

I dont want the help n training explanation

nick1505nick1505

Hi,

 

Conside the below EG: of Account 

 

Suppose you are having the following record:

Account Name = 'TestAccountOld';

 

So now if you update the recordName to say:

 

Account Name = 'TestAccountNew';

 

So trigger.new will return a list with the new value of Account i.e:

Account Name = 'TestAccountNew';

 

And trigger.old will return you the old value of that Account i.e:

Account Name = 'TestAccountOld';

 

Let me know if it works for you!

sunny.kapoor1306sunny.kapoor1306

Thanks

I understood the difference

 

is the coding same?

nick1505nick1505

Yes, you will mostly be using the trigger.old in update and delete case.

Try working with one example you will understand the difference yourself.

Also mark it as a solution if it solves your problem!

 

sunny.kapoor1306sunny.kapoor1306

I wrote a code for trigger.new

can i convert this into .old?

 

 

trigger titletext on Lead (before insert,before update) {
for(Lead e:trigger.new)
if(e.title==null)
{
e.title='Miscellenous';
e.industry='Bollywood';
}
}

nick1505nick1505

No. Trigger.new and trigger.old are the list of records provided to you by the trigger itself with trigger.new consisting of the new values and trigger.old consisting of the old values(prior to the change). 

If you can mention your requirement clearly it would help me better in helping you!

sunny.kapoor1306sunny.kapoor1306

sure sir

 

actually i just want a working eg of trigger.old which wud help me understand better