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
AlecSAlecS 

Check old value of sobject

Within this code, I want to check what's the OLD value of the field Status. This code gives me this error message:


Error: Compile Error: Method does not exist or incorrect signature: [LIST<Contract>].get(String) at line 4 column 70

 

I know that this is not a complete code - I just need someone to look at this part of the code and tell me how can I quickly check what is the old value of con.Status.

 

How can I fix this?

 

for(Contract con : trigger.new){
        if(con.Contract_Years__c != null && trigger.old.get(con.Status) != 'Active')

 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
Hengky IlawanHengky Ilawan

Hi AlecS,

 

You should reference the map instead of list.
Note that trigger old is only available in update and delete events.

 

for(Contract con : trigger.new){
    if (con.Contract_Years__c != null && trigger.oldMap.get(con.Id).Status != 'Active') {
        ...
    }
}

-Hengky-

All Answers

Naidu PothiniNaidu Pothini
for(integer i = 0; i < Trigger.new.size(); i++)
{
   if(Trigger.new[i].Contract_Tears__c ! = null && Trigger.old[i].Status != 'Active)
   {
   }
}

 try this.

Hengky IlawanHengky Ilawan

Hi AlecS,

 

You should reference the map instead of list.
Note that trigger old is only available in update and delete events.

 

for(Contract con : trigger.new){
    if (con.Contract_Years__c != null && trigger.oldMap.get(con.Id).Status != 'Active') {
        ...
    }
}

-Hengky-

This was selected as the best answer
AlecSAlecS

Perfect, it worked!

 

Thanks.