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
vajralavajrala 

I faced probloms with using newMap and oldMap

I am not understanding what is the use of newMap,oldMap and how it used.

please give me explanation with example

Best Answer chosen by Admin (Salesforce Developers) 
AmitSahuAmitSahu

NewMap - Map of the new values of the records. While creating or eiting. The values after edit is stored here.

OldMap - Map of the oldValues of the record. The record  that already exists in the database.

 

Example : Creating a New Case record :

 

CaseNumber =1;

Description = 'Test Case';

 

In this case there will be no oldMap, as there is no old values of this record.

NewMap will hold values : 1,'Test Case'

 

Let's say we made a change to the description (editied it)

Old Values : 

CaseNumber =1;

Description = 'Test Case';

NewValues:

 

CaseNumber =1;

Description = 'Test  Case edited';


OldMap :  1,'Test Case'

newMap:  1,'Test Case edited'

 

Hope did not confuse you...

All Answers

AmitSahuAmitSahu

NewMap - Map of the new values of the records. While creating or eiting. The values after edit is stored here.

OldMap - Map of the oldValues of the record. The record  that already exists in the database.

 

Example : Creating a New Case record :

 

CaseNumber =1;

Description = 'Test Case';

 

In this case there will be no oldMap, as there is no old values of this record.

NewMap will hold values : 1,'Test Case'

 

Let's say we made a change to the description (editied it)

Old Values : 

CaseNumber =1;

Description = 'Test Case';

NewValues:

 

CaseNumber =1;

Description = 'Test  Case edited';


OldMap :  1,'Test Case'

newMap:  1,'Test Case edited'

 

Hope did not confuse you...

This was selected as the best answer
vajralavajrala

Thanks you sir....