We deployed the below trigger from sandbox to production using outbound change set. No apex or test classes were created. Intent of trigger is to pass the first 255 characters from a Task Description field to a custom field that can be used in an Activity List View.
Trigger works as expected for system admin and highest role of role tree. All other users encounter the following error:
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger PassLongField caused an unexpected exception, contact your administrator: PassLongField: execution of BeforeUpdate caused by: System.StringException: Ending position out of bounds: 255: ()".
Click here to return to the previous page.
Any support would be really appreciated. Have no clue how to proceed. Thanks
trigger PassLongField on Task (before update) {
for (Task Task:System.Trigger.new){
//transfer long text field
if(Task.Description != NULL){
Task.List_View_Comments__c = String.valueOf(Task.Description).substring(0,255);
}
}
}