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
_tofu_tofu 

Casting trigger.newMap

This should be easy for whoever has done this before. I have the following block of code:

for(Id errorID : projectErrorIds) {
    trigger.newMap.get(errorID).Project_Stage__c.addError(System.Label.Project_Error);
}

It kicks out the following error: Field expression not allowed for generic SObject

Obviously, I need to cast it for it to work, but I don't know how. Thank you to anyone who can help!

 

Best Answer chosen by _tofu
_tofu_tofu
ANSWER:

for(Id errorID : projectErrorIds) {
    ((Project__c)trigger.newMap.get(errorID)).Project_Stage__c.addError(System.Label.Project_Error);
}