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
krprkrpr 

Triggers not firing on Contact When Validation Rules are in place

I am experiencing a strange behavior that none of the triggers are firing on contact when validation rules are active. The validation rule is blocking and I can't see trigger firing. Used to work before and nothing changed but after spring 12 release it stopped working.

 

If I deactivate Validation Rule the Trigger fires and does update .

 

 

Henry AkpalaHenry Akpala

Can you post the code and screen shot of validation rule?

Devendra@SFDCDevendra@SFDC

Hi,

 

When a record is saved with an insert, update, or upsert statement, the following events occur in order:

1. The original record is loaded from the database (or initialized for an insert statement)
2. The new record field values are loaded from the request and overwrite the old values
3. All before triggers execute
4. System validation occurs, such as verifying that all required fields have a non-null value, and running any user-defined validation rules
5. The record is saved to the database, but not yet committed
6. All after triggers execute
7. Assignment rules execute
8. Auto-response rules execute
9. Workflow rules execute
10. If there are workflow field updates, the record is updated again
11. If the record was updated with workflow field updates, before and after triggers fire one more time (and only one more time)
12. Escalation rules execute
13. All DML operations are committed to the database
14. Post-commit logic executes, such as sending email

 

Thanks,

Devendra

krprkrpr

Hi Henry,

 

Actually we have implemented Region by Country and Zip Code long back which takes the ZipCode and Country does a lookup and populates State Province and State Province Code. Which was working  as expected since long time. But we realized today after spring 12 release validation rule firing before triggers.

 

for POC I am posting something similar

 

Validation Rule
----------------

OR(
ISBLANK( City__c),
LEN(Zip_Postal_Code__c ) > 20
)

trigger
---------

trigger ValidationOrder on Contact (before insert, before update) {
    
    for(Contact c: Trigger.new){
        c.city__c='Hyderabad';
    }

}

 This is a basic trigger, when you try to create contact city should be auto populated. There is a validation rule in place which

 

looks for a condition if Zipcode >20 or city is blank it should fire. But in this scenario Validation rule is firing first which preventing triggers to fire. This is the case with Contact only. The same validation rule and trigger for account and other objects work fine.

 

we raised a call with salesforce and they are looking into it.

 

Thanks

Ram

krprkrpr

I wasn't expecting trigger order of execution which any one can find it from doc. I just want to highlight the issue.