0

I'm currently working on a Salesforce Community and used the 'Create a configurable self-reg handler' so I could map an existing contact to my user instead of creating a generic user. The default Apex class createUser method definition is the following one:

    global Id createUser(Id accountId, Id profileId, Map<SObjectField, String> registrationAttributes, String password) {

Since I added my own code to map the proper contact to my user, I need to create a test class to push my updated class in production. Below is code for my test class where I call the createUser method that was generated:

public with sharing class selfRegistrationTEST {

public static void selfRegistrationTest() {

    Schema.DescribeFieldResult F = User.Email.getDescribe();
    Schema.sObjectField T = F.getSObjectField();

    Map<SObjectField, String> m1;
    m1.put(T, 'customer@email.com'); 

    Id userId = AutocreatedConfigSelfReg123456789.createUser('accountIdhere', 'profileIdhere', m1, null);

}

However, I'm receiving the following error message which seems related to the Map I'm trying to use as an input variable.

Non static method cannot be referenced from a static context: Id AutocreatedConfigSelfReg123456789.createUser(Id, Id, Map<Schema.SObjectField,String>, String)

I researched this error and could not determine what was causing it or how I could resolve it so any help would be appreciated.

1

Your apex class looks something like this:

global class AutocreatedConfigSelfReg implements Auth.ConfigurableSelfRegHandler { 

    global Id createUser(Id accountId, Id profileId, Map<SObjectField, String> registrationAttributes, String password) {
            //Some bla bla coce
    }
}

createUser is an instance method, ie you can only invoke it using an instance.

Fix Create an instance of AutocreatedConfigSelfReg123456789 using new AutocreatedConfigSelfReg123456789() and then call create user method

public with sharing class selfRegistrationTEST {

public static void selfRegistrationTest() {

    Schema.DescribeFieldResult F = User.Email.getDescribe();
    Schema.sObjectField T = F.getSObjectField();

    Map<SObjectField, String> m1;
    m1.put(T, 'customer@email.com'); 

    Id userId = new AutocreatedConfigSelfReg123456789().createUser('accountIdhere', 'profileIdhere', m1, null);

}
  • Thanks @Pranay, that resolved my issue – rdarras Nov 25 '19 at 20:37

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.