You need to sign in to do that
Don't have an account?
problem while using UserType Field for custom save method in the controller
I am writing my own save method for the user custom page which is created by using the standard controller as a User.
when i am trying to write the controller code that time it is not allowing the use.UserType = cntr.UserType .Giving compilatin Error like
Error: Compile Error: Field is not writeable: User.UserType at line 51 column 6 |
Remaing fields are allowed to write.
Why it is not allowing to compile the controller?
Can anyone phased this situation?
how can i use for UserType Field.
For more clarity on my problem i am just giving my custom page code and controller code which is given below.
custom user Page :
<apex:page standardController="User" extensions="usercontroller" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="User Information">
<apex:inputField id="userFirstName" value="{!user.firstname}"/>
<apex:inputField id="userLastName" value="{!User.lastName}"/>
<apex:inputField id="userAlias" value="{!User.alias}"/>
<apex:inputField id="userEmail" value="{!User.email}"/>
<apex:inputField id="userUserName" value="{!User.UserName}"/>
<apex:inputField id="userLicense" value="{!User.UserType}"/>
<apex:inputField id="userEmailEncoding" value="{!user.title}"/>
<apex:inputField id="userCommunityNickName" value="{!User.communityNickName}"/>
<apex:inputField id="userrole" value="{!User.UserRoleId}"/>
<apex:inputField id="userProfileId" value="{!User.ProfileId}"/>
<apex:inputField id="userEmailEncodingKey" value="{!User.EmailEncodingKey}"/>
<apex:inputField id="userlanguage" value="{!User.LanguageLocaleKey}"/>
<apex:inputField id="userlocale" value="{!User.LocaleSidKey}"/>
<apex:inputField id="userTimezone" value="{!User.TimeZoneSidKey}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Custom controller:
public class usercontroller {
private User cntr;
private final ApexPages.StandardController controller;
public usercontroller(ApexPages.StandardSetController controller) {
}
//
public usercontroller(ApexPages.StandardController controller) {
this.controller = controller;
cntr= (User )controller.getRecord();
}
public PageReference Test()
{
PageReference pageRef = new PageReference('https://na6.salesforce.com/apex/newuser');
pageRef.setRedirect(true);
return pageRef ;
}
public PageReference Save()
{
User use = new User();
use.firstname = cntr.firstname;
use.lastName =cntr.lastName;
use.alias =cntr.alias;
use.email =cntr.email;
use.UserName =cntr.UserName;
use.UserType =cntr.UserType;
use.title =cntr.title;
use.communityNickName =cntr.communityNickName;
use.UserRoleId =cntr.UserRoleId;
use.ProfileId =cntr.ProfileId;
use.EmailEncodingKey =cntr.EmailEncodingKey;
use.LanguageLocaleKey =cntr.LanguageLocaleKey;
use.LocaleSidKey =cntr.LocaleSidKey;
use.TimeZoneSidKey =cntr.TimeZoneSidKey;
insert use ;
PageReference pageRef = new PageReference('https://c.na6.visual.force.com/apex/users');
pageRef.setRedirect(true);
return pageRef ;
}
}
use this code.. it works..
<apex:page standardController="User" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="1" >
<apex:inputField value="{!User.firstname}"/>
<apex:inputField value="{!User.LastName}"></apex:inputField>
<apex:inputField value="{!User.Alias}"></apex:inputField>
<apex:inputField value="{!User.email}"/>
<apex:inputField value="{!User.username}"/>
<apex:inputField value="{!User.UserRoleId}"></apex:inputField>
<apex:inputField value="{!User.UserType}"></apex:inputField>
<apex:inputField value="{!User.ProfileId}"></apex:inputField>
<apex:inputField value="{!User.IsActive}"></apex:inputField>
<apex:inputField value="{!User.emailencodingkey}"></apex:inputField>
<apex:inputField value="{!User.timezonesidkey}"></apex:inputField>
<apex:inputField value="{!User.localesidkey}"></apex:inputField>
<apex:inputField value="{!User.languagelocalekey}"></apex:inputField>
<apex:inputField value="{!User.receivesadmininfoemails}"></apex:inputField>
<apex:inputField value="{!User.receivesinfoemails}"></apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock></apex:form>
</apex:page>
Regards,
Mahendiran Jayavarma