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
Raquel RiemerRaquel Riemer 

Cannot change field type of a custom field referenced in Apex class or trigger

When running one of our $$ batch processes we encountered the error "STRING_TOO_LONG".

I see the field that is the issue - it is text 255

I see the trigger that is reference the field and causing the subject line Cannot change field type of a custom field referenced in Apex class or trigger when I try to make the field text area or long text

I cannot simply comment out the field as it is reference throughout the trigger. The error says Trigger.DonationDesignations: line 55, column 1: []  but this is all that is in that line  updatedOppList.add(Opp);

Any ideas what I can do here

PriyaPriya (Salesforce Developers) 

Hi Raquel,

I don't think there's any easy way to change a field that is being referenced in an apex class or trigger. There are two ways to get this done that I know of. Assuming you're working primarily in a sandbox: -

1.Comment out all the lines with that field in it in all classes and triggers.
2.Modify the field.
3.Deploy all the changed code and metadata to production
4.Uncomment all those lines of code
5.Deploy all the changed code to production

or

1.Make a new field with a new name.
2.Change every reference in your code to that new field.
3.Deploy changed code and new metadata to production
4.Move over any data from the old field to the new field

Please mark it best answer if the information is helpful.

Regards,

Priya Ranjan