Created
November 14, 2016 20:15
-
-
Save zachboyd/a16356b91d98f9b78b0987b7ddd70829 to your computer and use it in GitHub Desktop.
Inserts EntitySubscription record for user to follow a record. Helpful when you need people to automatically follow a record without logging in on behalf of them.
This file contains 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
// ID of record to follow | |
String recordId = '<my record id here>'; | |
// Create list of user ids | |
List<Id> userIdList = new List<Id>(); | |
// add ID of all users to list | |
userIdList.add( '<user id here>' ); | |
List<EntitySubscription> entitySubList = new List<EntitySubscription>(); | |
for( Id userId : userIdList ) { | |
entitySubList.add( new EntitySubscription( | |
ParentId = recordId, | |
SubscriberId = userId | |
)); | |
} | |
insert entitySubList; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment