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
jaelee125jaelee125 

Re-size image on rich text area field

I'm trying to re-size the image on a rich text area field. I got it working by adding style to img tag on the rich text area field.

For example:
Contact contact = [ SELECT Id, Picture__c FROM Contact WHERE Id = 'someId' ];
contact.Picture__c = contact.Picture__c.replace('<img', '<img style="height: 256px"'); 

Ideally we would like to use max height so images smaller than 256px won't get stretched out. However, max-height doesn't seem to work. If I add max-height, it clears it.

If I add max-height it saves it as style="".

SwethaSwetha (Salesforce Developers) 
HI jaelee,Do you see any error in the logs?Thanks
jaelee125jaelee125
Hi Swetha,

There are no errors in the log. Using the query editor in the dev console, if you set the value of a rich text area field to <img style="height: 20px;"></img>, it saves it as <img style="height: 20px;"></img>. However, if you set the value of a rich text area field to <img style="max-height: 20px;"></img>, it saves it as <img style=""></img>.
 
jaelee125jaelee125
Do you have any updates Swetha?