You need to sign in to do that
Don't have an account?

“Required fields are missing: [ProfileId]: [ProfileId]” when running Apex Class Test for ChatterAnswersAuthProviderRegTest
I am conducting an Apex test for ChatterAnswersAuthProviderRegTest, as I run this test, I encounter the following error message.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]
I am curious to know where to go about obtaining the the id of a Chatter Answers Profile. I have attempted to call ProfileId though it appears the profile Id's I have available do not seem to allow. Or any steps I need to take.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]
I am curious to know where to go about obtaining the the id of a Chatter Answers Profile. I have attempted to call ProfileId though it appears the profile Id's I have available do not seem to allow. Or any steps I need to take.
@isTest(SeeAllData=True) 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; insert(newUser); 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'); } } }
Example 1 :-
Example 2:- Please check below post :-
https://success.salesforce.com/issues_view?id=a1p300000008XHfAAM
Please mark this as solution if this will help you. So that if some one has same issue this post can help others
Thanks
Amit Chaudhary
All Answers
You are inserting newUser record in your test class in which profileId is missing which is required field for usr record .
Please check for that record which profile is requird if System Admin profile id ok for that record then you can add
newUser.ProfileId = p.Id; in line number 30 in trh code which you have post in forum .
Please let me know if it helps !!
Thanks
Manoj
Example 1 :-
Example 2:- Please check below post :-
https://success.salesforce.com/issues_view?id=a1p300000008XHfAAM
Please mark this as solution if this will help you. So that if some one has same issue this post can help others
Thanks
Amit Chaudhary