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
sindhu@demo.comsindhu@demo.com 

Can we @ a user using trigger on create of task

Can we @ a user on create of task? If so ,please let me know .

Thanks!

alouie_sfdcalouie_sfdc

Yes, you can use Chatter in Apex, which will be generally available in the Summer '13 release, to @-mention users with Apex code. You can read more about it in the documentation (http://www.salesforce.com/us/developer/docs/apexcodepre/index.htm). Here's a simple code snippet that shows you how to post a feed item containing an @-mention to someone's user profile:

 

// Post a feed item that has an @-mention.

String communityId = null;
ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;
String userToMention = '005xx000001TDn3'
String subjectId = '005xx000001TDn3';

ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = 'Hi there ';
messageInput.messageSegments.add(textSegment);

ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
mentionSegment.id = userToMention;
messageInput.messageSegments.add(mentionSegment);

textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = '. You have a new task.';
messageInput.messageSegments.add(textSegment);

ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.body = messageInput;

ConnectApi.FeedItem feedItemRep = ConnectApi.ChatterFeeds.postFeedItem(communityId, feedType, subjectId, input, null);