You need to sign in to do that
Don't have an account?

addError method issue
I have written this code block,
trigger Firm_LOB_Check on Fund__c (before insert, before update) {
for (Fund__c lfund : Trigger.new) {
Firm__c f = [select Line_Of_Business__c FROM Firm__c where Id = :lfund.Firm__c];
f.Name.AddError('Error');
for (Fund__c lfund : Trigger.new) {
Firm__c f = [select Line_Of_Business__c FROM Firm__c where Id = :lfund.Firm__c];
f.Name.AddError('Error');
}
}
I get the below mentioned error message when the trigger gets fired. If anyone got an idea please share.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Firm_LOB_Check3 caused an unexpected exception, contact your administrator: Firm_LOB_Check3: execution of BeforeInsert caused by: System.Exception: SObject row does not allow errors: Trigger.Firm_LOB_Check3: line 10, column 1
Review all error messages below to correct your data.
Apex trigger Firm_LOB_Check3 caused an unexpected exception, contact your administrator: Firm_LOB_Check3: execution of BeforeInsert caused by: System.Exception: SObject row does not allow errors: Trigger.Firm_LOB_Check3: line 10, column 1

Your trigger is acting on Fund__c, which would be in response to a user inserting or updating a Fund record. But you're adding the error to "f", which is a Firm__c object. The error message is telling you that you cannot add an error to that record -- the reason is, the user would never see it, because it's not the field they're modifying.

Thanks I got it later, its working fine now.