Newer Version Available
Apex Trigger: Prevent Closure of Work Orders with Open Line Items
The following trigger prevents users from closing a work order unless all its line items
have been closed. It’s a good way to ensure that all scheduled tasks are completed. The
accompanying unit test scans your code for issues.
To define a work order trigger in your org:
- In Lightning Experience, select Work Order in the Object Manager in Setup, then click Triggers. In Salesforce Classic, enter Work Orders in the Quick Find box in Setup, then click Triggers under Work Orders.
- Click New.
- Copy the trigger text and paste it into the text field.
- Click Save.