You need to sign in to do that
Don't have an account?
kMans2k
addError error
hey all,
excuse the pun.
I have a custom object FormA__c, which has a status field, Status__c.
What I would like to do is for the system to throw an error when the user first creates this object and chooses the status as something other thans "Status1".
In my trigger (trigger on before insert) I have the following code:
FormA__c[] Current = Trigger.new;
if( Trigger.isInsert ) {
if( Current[0].Status__c != 'Open' ) {
trigger.new.Status__c.addError('Status error');
}
}
if( Current[0].Status__c != 'Open' ) {
trigger.new.Status__c.addError('Status error');
}
}
Apex editor is complaining about the "trigger.new.Status__c.addError('Status error');" line:
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:FormA__c at line 8 column 7
if I change it to:
trigger.new.addError('Status error');
It reports the following error:
Error: Compile Error: Method does not exist or incorrect signature: [LIST:SOBJECT:FormA__c].addError(String) at line 8 column 7
your help is much appreciated.
Superfell
Trigger.new is an array, addError is method on an SObject, not an array. so you need trigger.new[0].addError or Current[0].addError