Skip to content

Instantly share code, notes, and snippets.

@zachboyd
Created November 14, 2016 20:15
Show Gist options
  • Save zachboyd/a16356b91d98f9b78b0987b7ddd70829 to your computer and use it in GitHub Desktop.
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.
// 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