You need to sign in to do that
Don't have an account?
shrey.tyagi88@tcs.com
Add multi word topic to chatter feed from apex!!
Hi Everyone,
I have written a trigger that posts a feed on Accdount record whenever a child gets inserted. This trigger works fine , but I am struggling to add multi word topics to it. Please finde the code given below:
trigger CreateChatterFeedOnAccount on Chatter_Feed__c (after insert) {
List<FeedItem> lstFeeds = new List<FeedItem>();
String BodyOfFeed;
if(Trigger.isInsert && Trigger.isAfter){
for(Chatter_Feed__c cf : trigger.new) {
FeedItem fi = new FeedItem();
fi.ParentId = cf.Account__c;
fi.Title= cf.Title__c;
BodyOfFeed = cf.Description__c;
if(cf.link__c!= null){
fi.Type = 'LinkPost';
fi.LinkUrl = cf.link__c;
}
if(cf.Topic_1__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_1__c;}
if(cf.Topic_2__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_2__c;}
if(cf.Topic_3__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_3__c;}
if(cf.Topic_4__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_4__c;}
if(cf.Topic_5__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_5__c;}
fi.Body=BodyOfFeed;
lstFeeds.add(fi);
}
}
if(lstFeeds.size()>0){
insert lstFeeds;
}
}
Now in the bold lines given above, if I add a topic that is of asingle word , it gets appended properly for eg if Topic_1__c= "Sunshine" then post adds #Sunshine . But if Topic_1__c= "My Topic" post adds #My Topic to it. So how do we add muti word topis via apex. I found another link , but was not able to figure out much from this. Please help.
http://salesforce.stackexchange.com/questions/31163/how-to-add-topics-names-containing-spaces-to-feeditem-using-hashtag-via-apex?rq=1
Regards
Shrey Tyagi
I have written a trigger that posts a feed on Accdount record whenever a child gets inserted. This trigger works fine , but I am struggling to add multi word topics to it. Please finde the code given below:
trigger CreateChatterFeedOnAccount on Chatter_Feed__c (after insert) {
List<FeedItem> lstFeeds = new List<FeedItem>();
String BodyOfFeed;
if(Trigger.isInsert && Trigger.isAfter){
for(Chatter_Feed__c cf : trigger.new) {
FeedItem fi = new FeedItem();
fi.ParentId = cf.Account__c;
fi.Title= cf.Title__c;
BodyOfFeed = cf.Description__c;
if(cf.link__c!= null){
fi.Type = 'LinkPost';
fi.LinkUrl = cf.link__c;
}
if(cf.Topic_1__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_1__c;}
if(cf.Topic_2__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_2__c;}
if(cf.Topic_3__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_3__c;}
if(cf.Topic_4__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_4__c;}
if(cf.Topic_5__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_5__c;}
fi.Body=BodyOfFeed;
lstFeeds.add(fi);
}
}
if(lstFeeds.size()>0){
insert lstFeeds;
}
}
Now in the bold lines given above, if I add a topic that is of asingle word , it gets appended properly for eg if Topic_1__c= "Sunshine" then post adds #Sunshine . But if Topic_1__c= "My Topic" post adds #My Topic to it. So how do we add muti word topis via apex. I found another link , but was not able to figure out much from this. Please help.
http://salesforce.stackexchange.com/questions/31163/how-to-add-topics-names-containing-spaces-to-feeditem-using-hashtag-via-apex?rq=1
Regards
Shrey Tyagi
if(cf.Topic_1__c!= null){BodyOfFeed=BodyOfFeed+' #['+cf.Topic_1__c+']';}