+ Start a Discussion
CpasslerCpassler 

Chatter Security - Adding someone to follow

I've created some triggers so the when an opportunity reaches a certain level the regional manager would start following the opportunity till it is closed and then it would stop.  Everything works fine when I'm logged in and going through the actions as an admin, but when I login as one of our sales people I get the following error. 

 

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []: Class.ChatterUtils.AddFollower: line 13, column 7

 

If I change the users profile and check Modify All Data then everything works, but for obvious reasons I don't want to open up everything to our users. 

 

Does anyone know if there is a way to make this work?

 

Thank you,

 

Craig

jgood2009jgood2009

Craig,

 

I had the exact same problem.  However, I have most of the code in a class, which is called by a trigger, and the class had sharing enabled.  Once I removed the sharing from the class, it worked perfectly.

 

Jennifer

SFDC_dreamforce2010SFDC_dreamforce2010

Hi Craig,

 

Do you mind sharing your code as i am planning to implement similar to what you have designed.

 

Thanks!

PasslerPassler

Hello,

 

You'll have to change a couple items, but here is the general idea - hope this helps.  I have a trigger that calls a class which the determines if I'm going to follow are remove the follow and that class calls these functions.

 

	public static void AddSOFollower(Id userId, Id objectToFollowId, String Chattertext){
		User[] FollowUser = [select Id, Name from User where lastname = 'Passler'];
		EntitySubscription[] EScheck = [select Id from EntitySubscription where ParentId = :objectToFollowId and SubscriberId = :FollowUser[0].Id];
		if (EScheck.size() == 0){			
			EntitySubscription ES = new EntitySubscription ();
			ES.subscriberId = FollowUser[0].Id; //userinfo.getUserId();  
     		ES.parentId = objectToFollowId;
    		insert ES;

			FeedPost fpost = new FeedPost();
			fpost.ParentId = FollowUser[0].Id; 
			fpost.Body = FollowUser[0].Name + ' ' + Chattertext;  // CurrentUser[0].UserRole.ParentRoleId;
			insert fpost;
		} 
	}
	
	public static void RemoveSOFollower(Id userId, Id objectToRemoveId, String Chattertext){
		User[] FollowUser = [select Id, Name from User where lastname = 'Passler'];
		EntitySubscription[] ES = [select Id from EntitySubscription where ParentId = :objectToRemoveId and SubscriberId = :FollowUser[0].Id];
		if (ES.size() != 0) {
			delete ES[0];
			FeedPost fpost = new FeedPost();
			fpost.ParentId = FollowUser[0].Id; 
			fpost.Body = FollowUser[0].Name + ' ' + Chattertext;
			insert fpost;			
		}
	}