+ 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:

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



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.

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.

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:

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

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');
            String middileString = f.Body.subStringAfter('</p>');
            String toShowString = beforeString + ':' +middileString;
            f.Body = toShowString.stripHtmlTags();
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.