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

  • can you paste your complete trigger code. You might getting error in some other place. – Tushar Sharma May 3 '17 at 10:04
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)
  • 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 '17 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....
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.