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
Dhilip DussaDhilip Dussa 

Hide String with apex

Is there any way to hide total URL

Dilip commented on https://login.salesforce/browse/JIP-123: this test comment.

Here I need to display: Dilip this test comment.
can you please help me.

Note: Some times URL will be different like https://login.salesforce/browse/JIP-12345:

Thanks
Dilip
AbhishekAbhishek (Salesforce Developers) 
Dhilip yes it is possible but for that, you need CName Implementation.

https://help.salesforce.com/articleView?language=en_US&type=1&mode=1&id=000335296


OR

If you want to rewrite the URLs of your force.com site's visual force pages, you can use the Site.UrlRewriter interface.
 
quoting the documentation:
"
For example, let's say that you have a blog site. Without URL rewriting, a blog entry's URL might look like this: http://myblog.force.com/posts?id=003D000000Q0PcN
With URL rewriting, your users can access blog posts by date and title, say, instead of by record ID. The URL for one of your New Year's Eve posts might be: http://myblog.force.com/posts/2009/12/31/auld-lang-syne
You can also rewrite URLs for links shown within a site page. If your New Year's Eve post contained a link to your Valentine's Day post, the link URL might show http://myblog.force.com/posts/2010/02/14/last-minute-roses"


I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
 
Dhilip DussaDhilip Dussa
Hi Abhishek,

Thank you for your quick response but my requirement is FeedItem, I need to write trigger

If anyone commented on Salesforce first line will same every time

Dilip commented on https://login.salesforce/browse/JIP-123: this test comment.

In this, I need to display only name and comment like Dilip this test comment.

Thanks
Dilip
AbhishekAbhishek (Salesforce Developers) 
yes but as it's a custom functionality.

I haven't done this functionality yet and You will not find the code snippet usually.
Abhishek BansalAbhishek Bansal
Hi Dilip,

You can use the String class methods to break the string as per your requirement.
For this particular requirement you can use the below code snippet:
String originaComment = 'Dilip commented on https://login.salesforce/browse/JIP-123: this test comment.';

String beforeString = originaComment.substringBefore('commented');
String afterString = originaComment.substringBefore('.');

String toShowString = beforeString + afterString;
You can also take help from other methods of the String by using the link below:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm

Let me know if you need any further help on this.

Thanks,
Abhishek Bansal.
Dhilip DussaDhilip Dussa
Thank you Abhishek, because of your guidance updated my code, working as expected


public class RemovePublicJiraContoller {
    
    public static void updateFeed(List<FeedItem> feedList){
        for(FeedItem f : feedList){

            String beforeString = f.Body.subStringbefore('on');
            system.debug('beforeString=========>>>>>'+beforeString);
            
            String middileString = f.Body.subStringAfter('</p>');
            system.debug('middileString=========>>>>'+middileString);
            
            String toShowString = beforeString + ':' +middileString;
            f.Body = toShowString.stripHtmlTags();
            system.debug('Body============>>>>>>>'+f.Body);
        }
    }
}  
Abhishek BansalAbhishek Bansal
If it is working fine than please choose a Best Answer and close this question so that it can also help others in future.