Created
December 22, 2014 20:00
-
-
Save mtetlow/b2975f45c101cd9fc1bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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