function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sudhIr NarayansudhIr Narayan 

Trim only 80 characters and save.

Hi, 

 I want to save only 80 character in a text field if user enters more than 80 i want to cut remaining and add only 80 characters please suggest me how to do this 

Thanks
Sudhir
Best Answer chosen by sudhIr Narayan
SarfarajSarfaraj
Trim the opportunity name using substring. Example
customObjectInstance.Name = opportunityInstance.Name.substring(0, 80);



All Answers

SarfarajSarfaraj
Hi Sudhir

1. Edit the text field and make if of length 80. It will accept only 80 characters.
2. Override the standard edit/create page using a VF and in the controller trim the field content using substring(0, 79).
sudhIr NarayansudhIr Narayan
Hi Akram,

    field is auto text name in custom object I am not able to provide lenght since its a auto text 

Thanks
Sudhir
SarfarajSarfaraj
If it is auto text how your user is able to provide an input?
sudhIr NarayansudhIr Narayan
This is happening in a trigger, When a opportunity is created it will insert a copy to custom object here we are mapping opportunity name to custom object name

SarfarajSarfaraj
Trim the opportunity name using substring. Example
customObjectInstance.Name = opportunityInstance.Name.substring(0, 80);



This was selected as the best answer