HomeGuidesDeveloper HubRelease Notes
Get supportBook a chat
Developer Hub
These docs are for v2.96. Click to read the latest docs for v2.208.

User Creation

When a Member is created, both an account and a contact are created and linked to them by default. However, you may want to define a custom action for when the member is created, such as create a community user.

If you need any other custom action to happen upon the Member’s subscription, follow the steps below:

Create Apex Class

In your Org, go to Setup and search for Apex Classes in the Quick Find box. Click New to add your class.

public class CustomUserCreation implements  UserCreation {

    // Static Org Settings to avoid SOQL limits
    private static Organization orgSettings {
        get{
            if (orgSettings == null) {
                orgSettings = [SELECT DefaultLocaleSidKey, LanguageLocaleKey FROM Organization].get(0);
            }
            return  orgSettings;
        }
        set;
    }

    // Static Profile Id to avoid SOQL limits
    private static Id profileId {
        get{
            if(profileId == null){
                profileId = [SELECT Id FROM Profile WHERE Name = 'Fielo Community'].get(0).Id;
            }
            return profileId;
        }
        set;
    }

    // Reflection Method
    public User getUser(Member__c member, Id contactId){

        // Some required fields
        String communityNickname = member.Name + String.valueOf(contactId).substring(12,15);
        String subAlias = (member.Name.length()>4) ? member.Name.substring(0,4) : member.Name;
        String alias = subalias;
        String timeZone = UserInfo.getTimeZone().getId();

        User newMemberUser = new User(
            Email = member.FieloPLT__Email__c,
            Username = member.FieloPLT__Email__c,
            LastName = member.Name,
            Alias = alias,
            emailencodingkey = 'UTF-8',
            ProfileId = profileId,
            ContactId = contactId,
            LocaleSidKey = orgSettings.LanguageLocaleKey,
            TimeZoneSidKey = UserInfo.getTimeZone().getId(),
            LanguageLocaleKey = orgSettings.LanguageLocaleKey,
            CommunityNickname = communityNickname
        );
        
        return newMemberUser;
    }
}

Once the class has been created, you’ll need to add it as a value in the required Program field.

Adding Value to the Program Field

Within the Program's data page, find the User Creation Class field (FieloPLT__UserCreationClass__c) and add the recently created class name as a value. You can also create a new field set, as explained in program settings fields, to add this field.

❗️

The custom class added in the program's field will be executed only when the member is created using the Member Service Class - more specifically the ones that have completed the Register Members: Registration Step 2 (FieloPLT.MemberService.finishRegistration).