+ Start a Discussion
d3developerd3developer 

Toggling Chatter Email Notifications

 

 

Is there some way to toggle email notifications via APEX code?

 

If possible, I'd like to be able to turn them off and on for all users.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
cloudcodercloudcoder

Ok I couldn't leave it alone. What about something like the following. This should get you pretty close to the data you want.




select id, createdbyid, createddate, createdby.name, type, FeedPost.body, FeedPost.title, parentid, parent.name,
FeedPost.contenttype, FeedPost.linkURL, FeedPost.id,
(select id, createddate, createdbyid, parentid, createdby.name
from FeedComments
order by createddate desc)
from UserFeed
where FeedPost.body <> null LIMIT 1000; 

All Answers

cloudcodercloudcoder

If you are talking about the Chatter email preferences are not currently exposed via the API. If you think it is important to expose though, definitely add an idea  There is however, a UserPreference, UserPreferencesDisableAutoSubForFeedswhich you might be able to do some fun things with. 

 

If you are talking about general emails, check out DMLOptions.EmailHeader for the ability to manage some email notification on a case by case basis (I already tried it on FeedPosts though).  

 

 HTH

 

d3developerd3developer

Well, I guess I can explain what I am trying to do and you can tell me if it can be done or if there is a better way to do it.

 

In order to get all of the information I need to build my Admin Charts (http://fwd4.me/IkQ), I query NewsFeed (like Chatter Bubbles). Even if I don't include any WHERE clause, it only gives me items back that are a part of the active user's feed. So, in order to get all the items that are in the feed, I am temporarily subscribing the active user to all other user's feeds and all other objects that I care about.

 

Whenever someone starts following you, you get an email (if Chatter email is enabled). So I get a lot of emails :)

 

Right now, I reset the subscriptions to the original list of subscriptions after it is finished executing the query on NewsFeed, so what I'd like to do is temporary disable the emails for the short time that the query is running, since none of the subscriptions are permanent. I would like to leave Chatter email updates enabled in general. 

 

I'm not sure if I can do this via DMLOptions. In the docs it says it only manages the following cases:

 

 

* Creation of a new case or task * Creation of a case comment * Conversion of a case email to a contact * New user email notification * Password reset

 

 

 

 

Does the Chatter email also utilize this?

 

As an aside, I would like to use a Logger object to follow everything but DevAngel said in the techTalk that records can't follow objects!   :smileysurprised:

Message Edited by d3developer on 03-23-2010 12:33 PM
cloudcodercloudcoder
Does the class you are using to query NewsFeeds include the 'with sharing' keywords? This will restrict access to only your records, rather than the broader permissions associated with an Apex class without 'with sharing' defined.
d3developerd3developer
Nope.
cloudcodercloudcoder

Do you want to post a code sample and I can see what you are trying to do. As with many things, there is more than one way to skin a cat.

 

cloudcodercloudcoder

I was re-reading for initial posts and I dont think you will be able to get all posts for all users from the newsfeed. This could potentially be massive amounts of data, and the platform limits that ability.

 

cloudcodercloudcoder

Ok I couldn't leave it alone. What about something like the following. This should get you pretty close to the data you want.




select id, createdbyid, createddate, createdby.name, type, FeedPost.body, FeedPost.title, parentid, parent.name,
FeedPost.contenttype, FeedPost.linkURL, FeedPost.id,
(select id, createddate, createdbyid, parentid, createdby.name
from FeedComments
order by createddate desc)
from UserFeed
where FeedPost.body <> null LIMIT 1000; 
This was selected as the best answer
d3developerd3developer

You are right. I can just query the feed for each of my Sobjects in order to do what I want.

 

 

Although this does present the problem of knowing which SObjects are generating feeds. My understanding (I think from something I read in the Dev Zone) is that there is no Describe call by which I can find out whether or not an object has a feed. Is that right?

seahorceseahorce

What does the USERPREFERENCESDISABLEAUTOSUBFORFEEDS field on the User object control?  If I set it to True, what behavior will it change?

d3developerd3developer

Although this should probably be on a new thread, I'm pretty sure that disables the subscription for feeds that a user would automatically be subscribed to (at the very least, objects created and/or owned by a user) .