Skip to content

Instantly share code, notes, and snippets.

@mtetlow
Created December 22, 2014 20:00
Show Gist options
  • Save mtetlow/b2975f45c101cd9fc1bc to your computer and use it in GitHub Desktop.
Save mtetlow/b2975f45c101cd9fc1bc to your computer and use it in GitHub Desktop.
@RemoteAction
global static boardInfoWrapper toggleFollowTask(string taskId){
//Find if there is a current record
//Need to use without sharing
List<EntitySubscription> existingList = trControllerWithoutSharing.queryWithoutSharing('Select e.SubscriberId, e.ParentId From EntitySubscription e WHERE e.SubscriberId=\''+String.escapeSingleQuotes(UserInfo.getUserId())+'\' AND e.ParentId=\''+String.escapeSingleQuotes(taskId)+'\' LIMIT 1000');
//If no, insert a new one
if(existingList.size()==0){
EntitySubscription follow = new EntitySubscription (parentId = taskId,subscriberid = UserInfo.getUserId());
Map<String, Schema.SObjectField> fields = Schema.SObjectType.EntitySubscription.fields.getMap();
if(fields.get('NetworkId')!=null){
//communities enabled, subs have network id
follow.put('NetworkId',Network.getNetworkId());
}
trControllerWithoutSharing.insertWithoutSharing(new EntitySubscription[]{follow});
}
//If yes, del the old one
else{
for(EntitySubscription record : existingList){
trControllerWithoutSharing.deleteWithoutSharing(new EntitySubscription[]{record});
}
}
return trTaskBoardController.getBoardInfo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment