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:


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!

Napiš komentář, díky!

Quickly edit records in Salesforce

There are features in Salesforce most users don’t know about, which can make their life easier and work quicker. Also reason why I hate to use record types as much as possible. And things I usually forget to tell new users.

Edit multiple records at once

It was here forever, in Classic you had to enable it and it was one of the first thing I enabled – enable multiple records at once from list view.

When you slowly move your mouse over records at list view and take a good look you might spot it – the cursor sometimes changes to pencil. That is the place!

Edit in list views

And it is also reason why Salesforce in Lightning allows you to wrap lines. The idea is simple – you might be able to edit records in a similar way as in Excel, directly in list views and then save it all at once!

When it doesn’t work?

There are a few reasons why you might not see pencil but rather a lock.

  • you have multiple record types in a view, in such case you need to filter for specific record type;
  • the field isn’t on a page layout;
  • the field is on a page layout but read only;
  • the field is DateTime or standard fields of specific types – read the whole list of exceptions at Salesforce site.

Quickly edit a specific field on a record

Ok, what if it isn’t possible to edit a field in list view but you still want to make it easy for users and minimise number of clicks?

Some users found out, that they don’t have to open a record, click on the pencil next to a field and edit the value, but they can click on the arrow of right side in a list view and edit right from there, in a dialog. Not bad, about one click less, it might be also quicker to load. But what if they want/need to open the detail, to check something and then update the value?

Quick Actions to win!

That’s exactly the moment for Update quick action. I love them from the moment Jodie showed them to me at London’s Calling and this is perfect example.

You create Update quick action and put the fields you need to be able to quickly edit on its layout. Plus you can predefine some values. And then just add it on a page layout and when user click on the button they can see and immediately edit the fields they need, plus the values can be preset for them. Click Save and they saved some time as it is usually way quicker than to edit the whole form.

Update Quick Action

Napiš komentář, díky!

How can you – as an admin – destroy developer’s code

Salesforce, the platform which prefers clicks to code. Which is pretty easy to learn (especially with the help of Trailhead) and people/admins/power-users feel (over)confident to make changes on their own, without consulting the original implementator. Or even you – as an implementator – forget some things which can destroy everything you created.

Looking for some examples, which might go wrong super easily?

New Field

There is nothing wrong with creating new fields, you cannot destroy anything as the app didn’t know about it anyway.

Well, unless you mark the field as required in its properties and then all integrations go wrong, as they don’t know they need to fill the field.

Solution? Set it mandatory on page layout, that way users have to enter value when editing the record, but it is ok for everything else.

Validation Rule

Business tells you they have some new validation you need to create and it will be no problem for any integration, as it provides all the values anyway.

The only problem is, that you forgot to check existing records and they don’t respect the rules, so things which runs in background or simple stuff like roll-up fields will stop working. And it is pretty confusing to users, when they want to create a new product on opportunity and get a message that account’s owner is from wrong department.

Solution: check in your validation rules that they fire only when the specific field is changed. And even then check existing records, if they fulfil the criteria.

Duplication Rules

Who wants to see duplicates in their system? No one, easy. The problem here is called Process Builder, because in APEX you can write the code in such a way that it can save the duplicate, just include the following:

Database.DMLOptions dml = new Database.DMLOptions(); 
dml.DuplicateRuleHeader.allowSave = true;
dml.DuplicateRuleHeader.runAsCurrentUser = true;
List<Database.SaveResult> sr = Database.insert(contactsToInsert, dml);

But then the Process Builder will fire on new contact and all of sudden it isn’t possible to tell it to allow save, even though it is enabled in your duplicate rule. And it will fail, I mean the APEX code will fail because of your process.

Solution: remove the process builder and code it, not aware of anything else.

State and Country Picklist

State and Country picklist is such a great thing, it really helps you to clean the list of countries the users use.

The downside is integration, where you need to pass/transform the values into something accepted by Salesforce. Of course you can change the integration values in Salesforce, but that expect that all systems will provide the same value. If not, your code needs to do the transformation, before you’ll realise this small change you have no idea why it fails all of sudden.

Sandbox folks, use sandbox!

I’m not fan of sandboxes (shame on me!), I don’t believe in them. And frankly, from my experience, your admin/power-user will not be able to test the examples above.

The reason is pretty simple – even if you show them how to run tests, the test will be most likely written in such way, that they will pass.

Hands up developers who write tests with random country name, who fills all fields on records (and even then when they add a new field it is possible to set validation in such way that test will pass but real life not), who have data factory set up in such way that it even don’t generate duplicates (when you don’t know how the client defines them) or rather create them to check that you will survive this thing.

We should’t blame the admins/power-users, remove their rights and force them to sandboxes. We need to explain, show, teach more … and they need to be willing to learn more. Till then, be ready for your code to be broken for unknown reason.

Why it failed?

This article also means that I – after a week – finally know why sometimes the records were created with wrong assignment.

It was quite a journey:

  1. the integration wasn’t handling duplicates gracefully, duplicate management has been turn on a while ago and no duplicate till that time;
  2. when the integration was updated (with the code above) the process builder which fired blocked it everything;
  3. the trigger from vocative app we installed wasn’t ready to be called from batch class (who would expect when writing tests for that trigger, that it might be called by record created from a batch class?);
  4. the State and Country picklist has been turn-on a while ago and after a few weeks finally there was a record with country specified, just not from the approved list.

Was great week, I learnt and reminded myself of a few things, hopefully you learnt something new as well. Doesn’t matter what is your role. Or didn’t you?

Napiš komentář, díky!

Change Data Capture Events

Change Data Capture Eventy Salesforce představil jako pilot již v releasu Winter 18 a rozšířil tak Streaming API o další typ eventy (těmi zbylými jsou PushTopic Event, Generic Event a Platform Event).

Co to vlastně Streaming API je? Jedná se o tzv. push technologii, publish/subscribe model. Jednoduše to znamená, že na jedné straně je vysílač, který vysílá eventy (server), k jejichž odebírání se mohou hlásit posluchači (klienti). Posluchačem těchto event může být jiný systém, a lze tak zajistit near-real time synchronizaci dat. Posluchačem může být také prohlížeč uživatele stejné Salesforce instance. A na tento způsob využití se dnes podíváme.

Change Data Capture Eventy fungují velmi jednoduše. O jejich publikování se Salesforce stará sám. Vy pouze musíte streamování povolit pro požadované Objekty. Vybrat si jich můžete až pět. Od této chvíle se při vytvoření, editaci nebo smazání záznamu daného objektu automaticky publikuje eventa.

Zbývá druhá část, a sice zajistit odběr těchto event pro uživatele SF. Zde už je to trochu více srandy a neobejdeme se bez práce vývojáře. Naštěstí Salesforce, taktéž ve W18, přišel s novou aura (a později i LWC) komponentou lightning:empApi. Té vy jen řeknete, ke kterému kanálu se má přihlásit (každý objekt má svůj kanál), a implementujete logiku zpracování těchto event a následný způsob notifikace.

Takže na jedné straně máme vysílač – Salesforce, který nyní automaticky streamuje veškeré změny na vybraných objektech, a na druhé straně máme připravené poslouchátko. To můžeme umístit třeba do utility baru, nebo na layout.

K čemu je to vlastně dobré? Využití je celá řada. Pojďme se podívat, jak a proč jsme Change Data Capture Eventy využili v Zonky, kde desítky uživatelů odbavují veškerou komunikaci a zpracovávají žádosti o půjčky.

Notifikace o novém emailu

Problémy, které jsme se s Change Data Capture Eventami rozhodli vyřešit, byly tři:

  1. Uživatel pracuje s Casem (nebo ho má otevřený v tabu a věnuje se jinému) a najednou se změní hodnota v nějakém poli. Uživatel se o této nové hodnotě nedozví, dokud stránku neobnoví. Toto je problém všude tam, kde na jednom záznamu může pracovat více lidí najednou, nebo dochází k updatu dat z externího systému, nebo třeba změnou na provázaném záznamu a následnou automatizací, scheduled akcí, atd.
  2. Uživatel má přiřazený Case a píše email klientovi, s využitím emailových šablon s podpisem. Co se stane, když je v průběhu psaní emailu Case přesunut do fronty (např. nějakým nezávislým procesem)? Email nebude podepsaný jménem uživatele, nýbrž jménem fronty.
  3. U emailů ještě zůstaneme. Je to k nevíře, ale když vám přijde odpověď na Case, který máte otevřený, uživatel není upozorněn a o emailu se dozví opět až po obnovení stránky.

Rozhodli jsme se tedy využít Change Data Capture Eventy a poslouchací okénko jsme přidali na layout Casu, kde, neviděno, čeká, jestli nedojde ke změně na záznamu. Samozřejmě je potřeba změny nějak vyfiltrovat a zpracovat (například asi nechceme uživatele notifikovat o změně záznamu, kterou právě provedl on sám) a rozmyslet, jakým způsobem uživatele notifikovat. My jsme například rozlišili upozornění na nový email a změny ostatní. A toto je výsledek:

Jak vypadá komponenta na stránce

A jak dlouho zabere samotná implementace? Úplný základ budete mít hotový za odpoledne. Níže pro představu sdílím, jak může vypadat kostra poslouchátka psaná v aura komponentě. V závislosti na složitosti logiky a požadavcích na vzhled počítejte s jednotkami dnů. Pokud využití Change Data Capture Event zvažujete, nepodceňte analytickou fázi. Seznamte se s limity (např. počet doručených Event/24 hodin) a omezeními (View All permission pro daný objekt) a zvažte, zdali je toto řešení pro vás tím nejvhodnějším.

Aura komponenta

Eliška Bušáková

Eliška Bušáková je Salesforce developerka a konzultantka ve společnosti Enehano Solutions. Dámy ji mohou znát také jako lektorku kurzů zaměřených na Salesforce administraci a vývoj, které od loňského roku Enehano zajišťuje pro skupinu Women in Tech.   

Napiš komentář, díky!

Some podcasts to listen to

If you don’t know this about me – I hate podcasts. The reason is, that I can read really quickly and listening to people is so slow, I cannot skim quickly through it or easily go back.

But that doesn’t mean I’m not willing to take part in one and I participated in two of them this year already. It is a great exercise as it force you to think about things you never give proper thought.

Lightning Champions Spotlight

We originally recorded this last year in August but then found out that the quality isn’t that great and had to re-record part of it.

We spoke with Kelly about Lightning, why I love flows, how to switch to Lightning and a few other things.

I found out that it is pretty funny that I don’t think twice about enabling Lightning and I do understand that people might feel they need additional training to be able to use that.

At the same time I feel that just turn it on is not enough – people have to get a training to fully utilise it (especially with all the new things like Einstein Search) and the admin/consultant should spend some time with them to see how they work and suggest improvements. I quite often offers flow to solve some problems, such as to visualise things from multiple records at one place or to quickly create records through some wizard. At the same time I can think about Quick Actions really changing the user experience a lot.

19 minutes long story short – don’t be afraid, switch to Lightning and get to learn flow.

Whatfix webinar

My second webinar this year was with Whatfix and we talked about user adoption.

I realised it is pretty connected with the previous one and it is really connected with marketing as well. I cannot really imagine and don’t agree with the approach that company (read management) decides to implement something, phase 2 is implementation and phase 3 are happy users using it.

Frankly, to me successful user adoption starts somewhere at the beginning of the project, maybe even sooner. The communication what needs and will be done, how, what it will bring, which systems it will replace, how it will simplify work.

Because when you just adopt another system, which will not simplify anything but people have to use it … then you can have just a wet dreams about user adoptions and any „relevant“ KPIs such as number of logins or number of new records doesn’t really tell you anything about user adoption. The moment when you hear about (good) user adoption is when you hear feedback how they use it or want to use it, how it helped them to get a new project and such things. If you hear just how many hours they reported or new records they created but never really get any outcome from the info they added and also no-one else got any real outcome from it – you just wasting time of your people.

You know what? I will never use the system, I have 10 clients with multi years projects and I can name them from top of my head.

This was the feedback from one of my client and I disagreed. But … he has a point and if someone above him cannot persuade him that someone else needs the info available in the system, then he would really waste time of his people.

Long story short – don’t hope that you will solve user adoption at the end, it will be nightmare for everyone. Start right at the beginning and ask marketing how to do that.

Napiš komentář, díky!