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

Which user fields to set for managed package


I have an app that allows administrators to create users within the application to avoid forcing them to learn how to use Setup / Users. I have this working in a manage package which I now need to install in to a DE to get the application through security review. When I tried to upload the package into the DE the upload failed with this message: 

Invalid field UserPermissionsChatterAnswersUser

I have had to set many of the user permission fields to make this feature work. The permission fields I have used are in the following code exceprt:
newUser.UserPermissionsCallCenterAutoLogin = false;
newUser.UserPermissionsChatterAnswersUser = false;
newuser.UserPermissionsInteractionUser = false;
newUser.UserPermissionsKnowledgeUser = false;
newUser.UserPermissionsMarketingUser = false;
newUser.UserPermissionsMobileUser = false;
newUser.UserPermissionsOfflineUser = false;
newUser.UserPermissionsSFContentUser = false;
newUser.UserPermissionsSiteforceContributorUser = false;
newUser.UserPermissionsSiteforcePublisherUser = false;
newUser.UserPermissionsSupportUser = false;

I could just comment out the offending field but a). that may cause other errors, and b). there may be other fields in the list that are invalid in different SF org levels.

I have read somewhere that I can use this notation:

newUser.put('UserPermissionsMarketingUser', true);

But I do not know if it will address the problem. I do not want to use trial and error, because it takes many steps and at least a day to create a new package and regression test.

Any ideas?

Best Answer chosen by Rustyboy
I managed to fix the package installating by using the object.put() notation, for example:

newUser.put('UserPermissionsMarketingUser', true);

However, this caused an error when running the class containing this code, so I put the code for each individual assignment in a try / catch block as below:
setUserField('UserPermissionsCallCenterAutoLogin', false);
setUserField('UserPermissionsChatterAnswersUser', false);
setUserField('UserPermissionsInteractionUser', false);
setUserField('UserPermissionsMarketingUser', false);
setUserField('UserPermissionsMobileUser', false);
setUserField('UserPermissionsOfflineUser', false);
setUserField('UserPermissionsSFContentUser', false);
setUserField('UserPermissionsSiteforceContributorUser', false);
setUserField('UserPermissionsSiteforcePublisherUser', false);
setUserField('UserPermissionsChatterAnswersUser', false);
setUserField('UserPermissionsSupportUser', false);

private void setUserField (string argUserField, boolean argValue)
   	// Wrap assignnment (put) in try / catch block to avoid failing when field does not exist
    try {
		newUser.put(argUserField, argValue);
	} catch (exception e) {
		// Do nothing

All is now working fine