1

In my community I have enabled self-registration option. It works fine, however, I would like to update some fields on the related contact record (e.g. Mailing Address) when the community user is created (through self-reg). I tried to do it using Apex trigger on User with trigger event "after insert". Unfortunately, the trigger blocked my self-registration process and community admin has received the following error:

There was an error in registering a user in site My_Community. The error message is: CommunityUpdateContactTrigger: execution of AfterInsert

caused by: System.DmlException: Update failed. First exception on row 0 with id 003V000000Vr9xpIAB; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301V00000005qyS. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

The Apex trigger looks as follows:

trigger CommunityUpdateContactTrigger on User (after insert) {
    if (Trigger.isInsert) {
        List contactIds = new List();
        List users = Trigger.new;
        for (User u : users) {
            if(!String.isBlank(u.ContactId))
                contactIds.add(u.ContactId);
        }
        if (!contactIds.isEmpty()) {
            Contact[] contacts = [SELECT MailingCity, MailingCountry
                                  FROM Contact
                                  WHERE Id IN :contactIds];

            for (Contact c : contacts) {
                for (User u : users) {
                    if (u.ContactId == c.Id) {
                        c.MailingCity = u.City;
                        c.MailingCountry = u.Country;
                    }
                }
            }
            update contacts;
        }
    }
}

I checked how the trigger works when the community user is created by internal user inside the org (new Contact -> Manage External User -> Enable Customer User ...). It turned out that it works fine: after saving a user, Contact fields specified in the trigger were updated. My first assumption is that there might be a problem with permissions of the user performing self-reg. From what I know, during self-registration we are logged in as a default site's guest user with a Guest License. This user has Create/Edit access on Contact object.

  • It looks like the error comes from one of your custom flow inside your org. This is not related to the trigger. – Martin Lezer Aug 11 '17 at 14:56
  • Thanks for the response. I deactivated all flows using User or Contact objects but I keep receiving the same error. When my Apex trigger is not active, the problem disappears. – michal_z Aug 11 '17 at 15:23
  • Did you check the process builder? – Martin Lezer Aug 11 '17 at 15:26
  • As Martin says remember that Flow Trigger errors are thrown by Process Builder as well as Flow. In fact the PB is the replacement of the old Flow Triggers, so that would be the cause. – Dave Humm Aug 14 '17 at 8:54
1

This error will be getting caused by Process Builder firing as that causes errors that are displayed as 'Flow Trigger'.

Check which Processes fire on Contact and User so that you can identify what is causing the error and see if you can alter them to prevent this trigger update causing the error to be thrown.

  • Thanks, @MartinLezer and Dave. You were both right! In my org there were, indeed, some active processes in Process Builder which were interfering my trigger (or the opposite way, I haven't figured out yet). Now, I hope I'll know how to clean this little mess! – michal_z Aug 14 '17 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.