Sunday 24 January 2021

How to get Image URL from a RichTextArea field

 Hi,

Here we are going to learn how to get an Image URL from a RichTextArea if someone adds an image in RichTextArea.

String decodedImageUrl;

 Matcher imgMatcher = Pattern.compile( '<img(.+?)>' ).matcher(<RichTextArea_FieldAPIName>);

// iterate each image tag found

        while ( imgMatcher.find() ) {        

            // get the image tag html

            String imageTag = imgMatcher.group();

            System.debug( 'imageTag=' + imageTag );

            String imageURL = imageTag.substringBetween( ' src="', '"' );

            System.debug( 'imageURL=' + imageURL );

            decodedImageUrl= imageURL.unescapeHtml4();

         }  

Reference:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_matcher_methods.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_pattern_methods.htm#apex_classes_pattern_and_matcher_pattern_methods


No comments:

Post a Comment

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...