You need to sign in to do that
Don't have an account?
Elsa Roussel
ChatterAnswersAuthProviderRegTest : unjustified Code Coverage Failure
When I try to deploy some component (without any link to chatter) i have the error :
"ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser(), Details: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId] Class.ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser: line 31, column 1"
the test class ask for a ProfileId, while i can't modify it.
Name Version Nom d'espace Type
API salesforce.com 33.0 API salesforce.com
____________________________________________________________________________________________________
@isTest
private class ChatterAnswersAuthProviderRegTest {
static testMethod void validateCreateUpdateUser() {
User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
System.runAs ( thisUser ) {
Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast',
'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
null, new Map<String, String>{'language' => 'en_US'});
ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration();
Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1];
reg.setSiteAdminUserId(adminUser[0].Id);
User newUser = reg.createUser(null, userData);
System.assert(newUser != null, 'A new user should have been created');
System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same');
System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same');
System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same');
Contact c = new Contact();
c.AccountId = (newUser.Username.split('@'))[0];
c.LastName = 'contactLast';
insert(c);
newUser.Alias = 'firstusr';
newUser.TimeZoneSidKey = 'America/Los_Angeles';
newUser.LocaleSidKey = 'en_US';
newUser.EmailEncodingKey = 'UTF-8';
newUser.LanguageLocaleKey = 'en_US';
newUser.ContactId = c.Id;
// newUser.ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1].Id; [try to add this but i can't save]
insert(newUser); // <= this is where the error is located :
Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast',
'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
null, new Map<String, String>{'language' => 'en_US'});
reg.updateUser(newUser.Id, null, updateUserData);
User dbUser = [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id];
System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated');
System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated');
System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated');
}
}
}
________________________________________________________________________________________________
"ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser(), Details: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId] Class.ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser: line 31, column 1"
the test class ask for a ProfileId, while i can't modify it.
Name Version Nom d'espace Type
API salesforce.com 33.0 API salesforce.com
____________________________________________________________________________________________________
@isTest
private class ChatterAnswersAuthProviderRegTest {
static testMethod void validateCreateUpdateUser() {
User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
System.runAs ( thisUser ) {
Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast',
'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
null, new Map<String, String>{'language' => 'en_US'});
ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration();
Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1];
reg.setSiteAdminUserId(adminUser[0].Id);
User newUser = reg.createUser(null, userData);
System.assert(newUser != null, 'A new user should have been created');
System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same');
System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same');
System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same');
Contact c = new Contact();
c.AccountId = (newUser.Username.split('@'))[0];
c.LastName = 'contactLast';
insert(c);
newUser.Alias = 'firstusr';
newUser.TimeZoneSidKey = 'America/Los_Angeles';
newUser.LocaleSidKey = 'en_US';
newUser.EmailEncodingKey = 'UTF-8';
newUser.LanguageLocaleKey = 'en_US';
newUser.ContactId = c.Id;
// newUser.ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1].Id; [try to add this but i can't save]
insert(newUser); // <= this is where the error is located :
Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast',
'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
null, new Map<String, String>{'language' => 'en_US'});
reg.updateUser(newUser.Id, null, updateUserData);
User dbUser = [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id];
System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated');
System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated');
System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated');
}
}
}
________________________________________________________________________________________________
I have the same problem. No sollution yet though. I'll let you know if i find something.
Kind regards,
Kasper
This may have something to do with it: https://success.salesforce.com/issues_view?id=a1p300000008XHfAAM
I tried some method, but i couldn't fix it for now, even with the link above but I can't make it work and I can't delete nether emptying those class on the client profile he need it.
We already contacted Salesforce supports about this problem and are waiting for their answer.
Best regards,
elsa
Has anyone resolved this?
Marc, the ChatterAnswersAuthProviderRegTest class doesn't exist in my sandbox but it is in production. Did you create this class in sandbox without any unit tests and include this in the deployment?
newUser.ProfileId = '00eD0000001msUC';
NOTE: The ID is a hard-coded but this solves the issue.
I have the same issue. It's pity that SalesForce refuses to solve cases like this one. Which was the reason to refuse it?
I am currently trying both solutions:
1) clear the test class as suggested by Marc ME. This is not a proper way to make things work, especially if the issue is generated by the system itself instead of by something on the user side.
2) hard-coding the ProfileId, as suggested by ab84. This solution is not working with our ORG: we are getting the error Error MessageSystem.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Chatter Answers User is not allowed for this License Type.: [UserPermissions]Stack TraceClass.ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser: line 32, column 1
Ab, which profile is your 00eD0000001msUC hard coded profile?
Thanks
https://trailblazer.salesforce.com/issues_view?id=a1p300000008ZX2AAM
Just in case anyone else comes here. The fix was to hard-code the Profile Id in the class to the "Chatter Answers" UserProfile Id.