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

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
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
Can you please post the code of test class(ChatterAnswersAuthProviderRegTest) if possible? It seems we are not assigning the value of profile id.
Can you please replace your test class code with following, Make sure create a backup of file before replacing it:
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.
@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');
}
}
}
The new line added is:
newUser.profileId = [SELECT Id FROM Profile WHERE Name ='Customer Portal Manager Custom' LIMIT 1].Id;