+ Start a Discussion
Srinu@dreamsSrinu@dreams 

Unable to update records in batch apex due to validation rule

My batch apex was working fine before the creation of validation rule,

After the creation of a validation rule I was not able to update records due to validation rule.

could you people please tell me,How can I avoid this error in batch class?

Noam.dganiNoam.dgani

You are trying to update records that do not comply with your validationn rule.

either update the validation rule logic or perform a data fix on the recorda that don't comply.

Srinu@dreamsSrinu@dreams

Whatever the data I am updating, that is valid for validation rule even I am getting error.

crop1645crop1645

Validation rules apply to record updates regardless of context:

* Standard page updates

* VF controller updates

* Triggers

* Apex scheduled jobs

* batch APEX

* AJAX toolkit

* API

* Data loader

...

 

If for some reason the batch apex should be immune to a specific validation rule, then recode that validation rule, if possible, to take into consideration the running user or running user profile of the batch apex job (or, have the batch apex job always set a checkbox field 'batchapexjobisrunning__c' to true, have the validation rule be aware of this checkbox field, and then clear the field in a workflow field update or after trigger.