Salesforce Asked by SachiDangalla on December 24, 2020
I have the following autocreated class: and I need to write a test class for that.
global class AutocreatedConfigSelfReg1587088360367 implements Auth.ConfigurableSelfRegHandler {
private final Long CURRENT_TIME = Datetime.now().getTime();
private final String[] UPPERCASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
private final String[] LOWERCASE_CHARS = 'abcdefghijklmnopqrstuvwxyz'.split('');
private final String[] NUMBER_CHARS = '1234567890'.split('');
private final String[] SPECIAL_CHARS = '!#$%-_=+<>'.split('');
// This method is called once after verification (if any was configured)
// This method should create a user and insert it
// Password can be null
// Return null or throw an exception to fail creation
global Id createUser(Id accountId, Id profileId, Map<SObjectField, String> registrationAttributes, String password) {
User u = new User();
u.ProfileId = profileId;
for (SObjectField field : registrationAttributes.keySet()) {
String value = registrationAttributes.get(field);
u.put(field, value);
}
u = handleUnsetRequiredFields(u);
generateContact(u, accountId);
if (String.isBlank(password)) {
password = generateRandomPassword();
System.debug('Generated random password: ' + password);
}
Site.validatePassword(u, password, password);
if (u.contactId == null) {
return Site.createExternalUser(u, accountId, password);
}
u.languagelocalekey = UserInfo.getLocale();
u.localesidkey = UserInfo.getLocale();
u.emailEncodingKey = 'UTF-8';
u.timeZoneSidKey = UserInfo.getTimezone().getID();
insert u;
System.setPassword(u.Id, password);
return u.id;
}
}
The test code I’m writing:
@isTest static void testCreatetUser(){
AutocreatedConfigSelfReg1587088360367 handler = new AutocreatedConfigSelfReg1587088360367();
Account account = TestDataFactory.createAccount('HH_Account');
String EXTERNAL_USER_PROFILE = 'Apply App';
Profile profile = [SELECT Id, Name FROM Profile WHERE Name=:EXTERNAL_USER_PROFILE];
String password = '';
Map<SObjectField, String> registrationAttributes = new Map<SObjectField, String>();
handler.createUser(account.Id, profile.Id, registrationAttributes, password);
//TODO assertions
}
However, I’m getting an unknown exception while executing the line:
Site.validatePassword(u, password, password);
The exception is:
System.UnexpectedException: Salesforce System Error: 1762244533-9839 (-183289280) (-183289280)
Any direction on how to solve this would be much appreciated.
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP