0

I'm trying to see if the Priority value on Case changed but I get the error below and I can't figure out why.

        for(Case c: (List<Case>)Trigger.New) {
        if(setRecordTypeIds.contains(c.RecordTypeId)) {
            if(Trigger.oldmap.get(c.id).Priority!=c.Priority) {
                do somthing....
            }
        }
    }

Error - Field expression not allowed for generic SObject

1
  • can you paste your complete trigger code. You might getting error in some other place. May 3, 2017 at 10:04

2 Answers 2

1

you probably reference Trigger.oldMap in class, not in the trigger.

Trigger.oldMap is generic which contain: map<Id, sObject>, therefore it's not familiar with specific sObject field.

You should either cast the trigger.oldMap to the relevant type:

map<id, Case> caseOldMap = (map<id, Case>) trigger.oldMap;

Or, when calling the relevant function from trigger, pass the map as parameter

public void myFunction(map<id, Case> oldMap)

From trigger call:

myFunction(trigger.oldMap)
1
  • Liron you are correct, I'm calling Trigger.oldMap in class, not in the trigger. I used map<id, Case> caseOldMap = (map<id, Case>) trigger.oldMap; as suggested and it worked, thank you!
    – Json
    May 3, 2017 at 10:47
1

Type cast Trigger.old as well:

for(Case c: (List<Case>)Trigger.New) {
    if(setRecordTypeIds.contains(c.RecordTypeId)) {
        Case oldCase = (Case) Trigger.oldmap.get(c.id);
        if(oldCase.Priority!=c.Priority) {
            do somthing....
        }
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .