function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chrisjanning2chrisjanning2 

Programmatically have a group/user follow an object upon creation

When a new record is created off of a custom object, I need to have a specific group and/or user automatically follow it.

Vinit_KumarVinit_Kumar

I don't think there is a way to follow a record programmatically.You have to manually click on follow link.

chrisjanning2chrisjanning2

Ok then if not following then add a user/group as owner?

Vinit_KumarVinit_Kumar

You can write an Apex Trigger on insert/update events which would assign the owner of record.

 

 

chrisjanning2chrisjanning2
Thanks. Do you have some sample code that would do this?
Vinit_KumarVinit_Kumar

Try below :-

 

trigger AssignOwner on Lead (before insert,before update) {

User u = [select id from user where name = 'Vinit Kumar'];

for(lead l:trigger.new)
{
l.ownerid=u.id;
}