Skip to main content
fixed wrong tag
Link
Mohith Shrivastava
  • 91.9k
  • 19
  • 161
  • 214
added 454 characters in body
Source Link

I am doing bulk cloning of records and modifying some field values and reinserting records inside the future method, As the DML happens in the future method if there are any DML failures due to validation rules, not able to report to the user on UI.

Is there a way in apex, where I can run validation rules against sobject records and know the failures in advance in realtime before pushing it the future method? The object has around 25 validation rules, I don't want to implement again in apex.

I am from ruby on rails background, Rails has a option to validate record beforehand i.e. before actual DML. I am looking for something this way in apex.

Example rails:

user_details = UserDetails.new
user_details.valid?
#=> false
user_details.errors.full_messages
#=> ["Name can't be blank", "Email can't be blank"]
user_details2 = UserDetails.new("Phil", "Phil's email")
user_details2.valid?
#=> true

I am doing bulk cloning of records and modifying some field values and reinserting records inside the future method, As the DML happens in the future method if there are any DML failures due to validation rules, not able to report to the user on UI.

Is there a way in apex, where I can run validation rules against sobject records and know the failures in advance in realtime before pushing it the future method? The object has around 25 validation rules, I don't want to implement again in apex.

I am doing bulk cloning of records and modifying some field values and reinserting records inside the future method, As the DML happens in the future method if there are any DML failures due to validation rules, not able to report to the user on UI.

Is there a way in apex, where I can run validation rules against sobject records and know the failures in advance in realtime before pushing it the future method? The object has around 25 validation rules, I don't want to implement again in apex.

I am from ruby on rails background, Rails has a option to validate record beforehand i.e. before actual DML. I am looking for something this way in apex.

Example rails:

user_details = UserDetails.new
user_details.valid?
#=> false
user_details.errors.full_messages
#=> ["Name can't be blank", "Email can't be blank"]
user_details2 = UserDetails.new("Phil", "Phil's email")
user_details2.valid?
#=> true
Source Link

How to validate sobject records against existing custom object validation rules using apex?

I am doing bulk cloning of records and modifying some field values and reinserting records inside the future method, As the DML happens in the future method if there are any DML failures due to validation rules, not able to report to the user on UI.

Is there a way in apex, where I can run validation rules against sobject records and know the failures in advance in realtime before pushing it the future method? The object has around 25 validation rules, I don't want to implement again in apex.