2

I have a trigger and a part of the trigger acts as a validation rule and it will fire an validation message whenever a user tries to create a Work order on an Expired entitlement. So now I don't see any error in trigger's Helper class but when I create a work order on an expired entitlement, I am seeing a Different message and I Don't think it is an error as I am not being notified about it by Salesforce.

I encounter the following error:

Error: Invalid Data. Review all error messages below to correct your data. Apex trigger sm1e.WorkOrderTrigger caused an unexpected exception, contact your administrator: sm1e.WorkOrderTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Work order cannot be updated, since Entitlement of this work order is not active.: []: (sm1e)

What changes do I need to make?

3
  • In the future, please edit your post with any clarifications.
    – Adrian Larson
    Commented May 1, 2017 at 14:23
  • Sure. I Doubled checked all the validation rules on this object but no rule is blocking this trigger Commented May 1, 2017 at 14:40
  • Validations via Apex can also cause this exception.
    – Adrian Larson
    Commented May 1, 2017 at 14:41

1 Answer 1

1

The validation rule clearly says that you are trying to create work order under a Entitlement which is inactive. You need to activate the Entitlement before creating work orders.

You can remove the end date or extend the end date from today's date to make Entitlement as active.

Entitlement detail

6
  • yeah. I know that the Entitlement is In-active. That is the Whole point. No user should be allowed to create a Work order if the Entitlement is In-active. If some one tries to, then the following Validation message has to popup on the top of the page "Work order cannot be updated, since Entitlement of this work order is not active" this is the custom text i had on the error Condition ( order.addError('Work order cannot be created, since Entitlement of this work order is not active.'); ). My concern is why am i seeing a long error message. i want to see only my validation message Commented May 1, 2017 at 14:46
  • because it is getting generated from trigger. The validation message is getting wrapped into the exception message. Commented May 1, 2017 at 14:49
  • How Can I modify it? Commented May 1, 2017 at 14:50
  • you can write your own custom message and try to consume that error and show the error. But errors those are getting generated from trigger, it doesn't allow to show only the actually error message. It will show like that. If you use visualforce page then that could be easily achievable by <apex:pagemessages/> Commented May 1, 2017 at 14:59
  • One last question: we have 6 record types on this object. all record types uses this trigger. so do i need create those many VF pages because fields on each record type is almost different from the other Commented May 1, 2017 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .