[SalesForce] Updating Contact record after self-registration in Community

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.

Best Answer

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.