function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eddie HogueEddie Hogue 

chatteranswersauthproviderregtest.cls required field missing profileid

Everytime we try to deploy a changed trigger or page we get this error from the saleforce object blocking us from getting our changes we need into production. Salesforce refuses to fix the issue.

Apex Test Result Detail
Time Started 4/23/2015 10:49 AM
Class ChatterAnswersAuthProviderRegTest
Method Name validateCreateUpdateUser
Pass/Fail Fail
Error Message System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]
Stack Trace Class.ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser: line 31, column 1

Does anyone know how to fix this or get salesforce to fix their problems?

Thanks for looking at the issue. Eddie
Pankaj_GanwaniPankaj_Ganwani
Hi Eddie,

Can you please post the code of test class(ChatterAnswersAuthProviderRegTest) if possible? It seems we are not assigning the value of profile id.
Eddie HogueEddie Hogue
Hi Pankay Thanks for the look… here is the code! @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{'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{'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 had found one article that mentioned putting this line of code in: newUser.ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1].Id; but it complains about the license type not permitted…any help would be appreciated. Again Thanks Eddie
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please replace your test class code with following, Make sure create a backup of file before replacing it:
 
@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{'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 Platform User' LIMIT 1].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{'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'); 
 } 
} 
}

FYI : I have used the Standard Platform User profile since license type for this profile is Salesforce Platform and I assume it is available in Production. If you still get any error, please check in the company information for the available licenses in Production and accodingly update the code with corresponding profile.
Eddie HogueEddie Hogue
Pankaj, I replaced the code in the Force.com IDE Eclipse (with previous version backup) – there error is: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Chatter Answers User is not allowed for this License Type.: [UserPermissions] I have also tried System Administrator and Chatter Free User with the Standard User and your choice of Standard Platform User. One interesting additional note – I went into our Sandbox and noticed the code in this class does not match the code in production org. They are both supposed to be on Spring ’15 so not sure why that is the cast. The version is our sandbox looks more like your version… I did try a change set from the sandbox to production but it fails with same messages, etc. Thanks Eddie
Eddie HogueEddie Hogue
This is the version of code from our sandbox, I tried a change set with it as-is and uncommenting the new lines that are not in prod org:

@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);
            
            //p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];            
            //UserRole ur = [Select PortalType, PortalAccountId From UserRole where PortalType =:'CustomerPortal' limit 1];
            
            newUser.Alias = 'firstusr';
            newUser.TimeZoneSidKey = 'America/Los_Angeles';
            newUser.LocaleSidKey = 'en_US';
            newUser.EmailEncodingKey = 'UTF-8';
            newUser.LanguageLocaleKey = 'en_US';
            newUser.UserPermissionsChatterAnswersUser = false;
            newUser.ContactId = c.Id;
            //newUser.profileId = p[0].Id;
            //newUser.UserRoleId = ur.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');
        }
    }
}
Derrek Harrison 1Derrek Harrison 1
If anyone is still struggling with this, the solution for us was to set the ProfileId for the newUser record to the Id of the Profile named 'Customer Portal Manager Custom'. This was the Profile listed in an unrelated example in the Setting Up Chatter Answers document.

The new line added is:
newUser.profileId = [SELECT Id FROM Profile WHERE Name ='Customer Portal Manager Custom' LIMIT 1].Id;