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
Sudhakar ReddySudhakar Reddy 

Triggers

Please explain me what is trigger.old ?

 

i amnot expecting definition.I am expecting explanation with example.

Rajesh SriramuluRajesh Sriramulu

Hi

 

for eg:

in trigger when u r goign to inset account record and update

then u can put see previous or old value is which is insert(test) and new value is (post)

Account acc = new account();

acc.name='test';

insert acc;

acc.name='post';

update acc

system.debug(trigger.OldMap.get(acc.Id).name);

 

Regards,

Rajesh.

Shreya...Shreya...

Trigger.old is one kind of generic map kind of functionality.

 

You can hold the vales in map as well as in list also.

 

 

Example you written one trigger which works on Contact after update

suppose contact objContact = new contact();

objContact.Name = test'';

insert  objContact;

 

objContact.Name = test123389465'';

update objContact;

if you ask the trigger.old vale then it will give us the vale which are before fireing the trigger.

it mesas in the above case trigger.old value says the contact.name is  test

and trigger.new vale says the contact.name is  test123389465

 

Regards,

Shreyaaa