You need to sign in to do that
Don't have an account?
developer_force
Field expression not allowed for generic SObject
Hi,
Need help with the error below
Here is the trigger handler class where iam implementing the before insert trigger
public void OnBeforeInsert(Sales_Target__c[] newRecords){
newRecords = trigger.new;
for(Sales_Target__c newSalesTarget : newRecords)
{
if ((newSalesTarget.Officer_Code__c != null) &&
(newSalesTarget.Officer_Code__c= System.Trigger.oldMap.get(newSalesTarget.Id).Officer_Code__c))
}
and the error i got is "Field expression not allowed for generic SObject '' at the line highlighted in red. Not sure what that mean.
Thanks
Your code appears to be sound - I know that the one thing that always bites me when dealing with INSERT triggers and Ids - that when you specify "before insert" - your records don't have an Id yet. Try flipping to "after insert" and see if that resolves the issue?
-Andy
Yes. I changed the code instead like this
public void OnBeforeInsert(Sales_Target__c[] newRecords){
newRecords = trigger.new;
for(Sales_Target__c newSalesTarget : newRecords)
{
Sales_Target__c[] salesTarget = [Select Id, Officer_Code__c , Target_Period_End__c , Target_Period_Start__c from Sales_Target__c
where Officer_Code__c =:newSalesTarget.Officer_Code__c];
if(salesTarget.size()>0){
//some error message
}
}
Pls let me know if that looks good!!!!
Thanks
I was facing same issue while comparing Trigger.newMap.get(Id).Status__C with objCandidate.Status__C
But I tried in following way and it works
sObject candidate = Trigger.newMap.get(candidate.Id);
candidate .get('Ass__Status__c') ==objCandidate.Status__c
@Andy
We can get the id in case of "before insert " with Trigger.new
In Trigger.new and Trigger.old id's are same but records detail are different.