You created a text field based on business requirements, everything gets implemented to production and now requirements changed where you need to change the field to a rich text field. To add to that you have added apex references to the field. If you check the UI go to the field you want to change to a rich text –> Edit –> Change Field Type and you don’t see that as an option:
Next you may be thinking it is not possible, then everything that you need to do in order to change the Text field to a Rich Text field comes to mind. This may include:
If you have a data and recovery tool you could use that to make things a little easier but still not much. A lot of changes for one field switch. There is an alternative method as long as the only reference is through Apex. Unfortunately Flows and Formula References will error (discussed below).
If you tried to retrieve the metadata for the text field (Test_Change_to_Rich_Text__c in this example):
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Test_Change_to_Rich_Text__c</fullName>
<externalId>false</externalId>
<label>Test Change to Rich Text</label>
<length>255</length>
<required>false</required>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>false</unique>
</CustomField>
and change it to Rich Text metadata:
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Test_Change_to_Rich_Text__c</fullName>
<externalId>false</externalId>
<label>Test Change to Rich Text</label>
<length>32768</length><!-- Length must be greater than 255 -->
<trackTrending>false</trackTrending>
<type>HTML</type>
<visibleLines>10</visibleLines><!-- must be 10 lines or greater -->
</CustomField>
Then deploy you will get the following error in Setup –> Deployment Status error: Conversion to Html only supported from LongTextArea
This at least indicates you can convert a Long Text to a Rich Text. Next you are thinking let’s change the field from Text to Long Text to Rich Text, so you try that via the UI and receive a validation error:
Even though this fails in the UI if you try this even a metadata deployment it will work:
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Test_Change_to_Rich_Text__c</fullName>
<externalId>false</externalId>
<label>Test Change to Rich Text</label>
<length>32768</length>
<trackTrending>false</trackTrending>
<type>LongTextArea</type>
<visibleLines>10</visibleLines>
</CustomField>
Then you can deploy the Rich Text Metadata again. Now you have a Rich Text field that was a Text field!
If you are trying the above alternative method and you receive the following error: Cannot change type due to existing data . This occurs when the field you are trying to change is referenced from a formula or a flow (even inactive versions). To get the above to work you would need to comment out the formula references which can be done with ‘/* <field reference> */’. Unfortunately, there is no quick solution with flows. All versions would need to be deleted.
Checkout My New Course:
Crush It As A Salesforce Developer: Mastering Apex
Test Your Knowledge:
Try the new Salesforce Developer Quiz