Post to Chatter when new user is created

Two motivations for writing this post. The first one was customer of mine, who wanted to add a new community user to a few Chatter groups, based on some variables. The second one was Matt Brown, who wanted to post to a user Chatter feed upon joining.

Both solutions are super simple, till the moment they will become complex. And both face the same challenge.

First of all, create a process builder, which will start it. Nothing fancy here except the delay – you cannot run the flow (or update anything on user) in the same operation as you would get an mixed DML error. The easiest way out of this problem is to set it as scheduled action which runs 0 days after created date and problem is solved.

Process builder to start flow

Second part is the flow, which is super simple, it has just one design element – Create new record. A few fields are needed, I found important the Network Scope, which is the id of the community (I know, I know, hardcoded).

Flow definition

If you want to add them to some groups you need to create Group Member records with Group id, member id, network id and collaboration role.

Done, that was easy.

Not that quickly!

It was easy and it works great. As long as you create your users as an admin. The moment you will allow them to self register it will fail., most likely with the following error:

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: Entity is read-only: FeedItem.

The problem is, that the records are created by guest user and you cannot really extend its rights. And from what I found it looks that writing some APEX will not help.

I tried Platform Events, because they looks awesome, but no success. The problem is that you have no running user under which identity you can run the action. One other solution was to send email to Email Service and write the code to handle it. But that means code.

The third way I tried was the Mass Action Scheduler written by famous Douglas C. Ayers. It is a managed package which you install, add Named Credentials and do some simple configuration. And it is so powerful!

Mass Action Scheduler

First of all you install the package via one of the link at Release Notes (the latest, right).

It will tell you how to proceed with the configuration and automatically create all the need things. All you have to do is to wait (we are quite good at such things in these times) and then edit Named Credentials, save and enter your login details. Now the real fun starts.

Create a new configuration, choose some nice name and Named Credentials it should use.

Mass Action Configuration 1

Second step – choose source of your data. This one is a bit tricky, as you cannot relate to something like „no processed yet“, so I selected all created today and do the checking in my flow. But you can also update the flow above with some updating of user record and here select only those relevant one.

Mass Action Configuration 2

Third one is choosing the right flow.

Mass Action Configuration 3

Fourth one is about mapping fields – your flow has one input variable and this one is available here.

Mass Action Configuration 4

Last one – when it should run. I chose every hour every day, Salesforce will handle it.

Mass Action Configuration 5

Done. Cross your finger, let first user self-register and on the hour you will know, whether you succeeded. I hope that you will, as did I. Good luck!

Zajímá mě tvůj názor