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
mat_tone_84mat_tone_84 

trigger validation error - alert message in wrong section

hello, I use this code for validation of opportunity.

 

trigger convalidation_opportunity on opportunity (after update) {
    list<opportunity > list_opp= new List<opportunity >();
    for (opportunity o: Trigger.new) {    
        list_opp.add(o);
        }    
    if (list_opp.get(0).stagename== 'test value'){
        if (list_opp.get(0).test_field__c == null){
            list_opp.get(0).test_field__c.adderror('check this field');  
        }

if(list_opp.get(0).field__c == null){
list_opp.get(0).field__c.adderror('check this field');
}
} }

 If I work on opportunity in edit mode(by clicking on edit), the error will be show at the top of opportunity page, instead if I work with "Inline Editing" the error will be show near the field.

I have about 30 "if condition" and If I work on edit mode, I don't understand where is the field with error, but I have about 30 error in the top of page.

How can I solve this ?

thanks

 

 

ca_peterson_oldca_peterson_old

The after triggers fire well, after, the comit to the database (or try to), and rollback the transaction if they fail.

What this means in practical terms is that adding errors to a field only works the way you want on before triggers.