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
Dhilip DussaDhilip Dussa 

create a user By using visualforce standard controller only

Hii..

create a user By using visualforce standard controller only
Raj VakatiRaj Vakati
Use this code  and create a button and expose this to UI 
<apex:page standardController="User">
    <apex:form>
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!user.name}"/>
                <apex:inputField value="{!user.firstname}"/>
                <apex:inputField value="{!user.lastname}"/>
                <apex:inputField value="{!user.email}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Dhilip DussaDhilip Dussa
I wrote the same logic but user is not inserting
 
Dhilip DussaDhilip Dussa
<apex:page standardController="user">
    <apex:form>
    <apex:pageBlock>
    <apex:pageBlockSection>
        <apex:inputField value="{!user.firstname}"/>
        <apex:inputField value="{!user.lastname}"/>
        <apex:inputField value="{!user.Email}"/>
        <apex:inputField value="{!user.profileid}"/>
        <apex:inputField value="{!user.CommunityNickname}"/>
       
        <!--<apex:inputField value="{!user.UserLicense}"/>-->
        
        </apex:pageBlockSection>
    </apex:pageBlock>
        <apex:commandButton value="save" action="{!save}"/>
    </apex:form>
</apex:page>
SarvaniSarvani
Hello Dhilip,

Try the below code. User object has additional required fields in addition to your fields.
<apex:page standardController="user">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockSection >
        <apex:inputField value="{!user.firstname}"/>
        <apex:inputField value="{!user.lastname}"/>
        <apex:inputField value="{!user.Email}"/>
        <apex:inputField value="{!user.profileid}"/>
        <apex:inputField value="{!user.username}"/>
        <apex:inputField value="{!user.languagelocalekey}"/>
        <apex:inputField value="{!user.localesidkey}"/>
        <apex:inputField value="{!user.timezonesidkey}"/>
        <apex:inputField value="{!user.emailencodingkey}"/>
        <apex:inputField value="{!user.alias}"/>
        <apex:inputField value="{!user.CommunityNickname}"/>
       
        <!--<apex:inputField value="{!user.UserLicense}"/>-->
        
        </apex:pageBlockSection>
    </apex:pageBlock>
        <apex:commandButton value="save" action="{!save}"/>
    </apex:form>
</apex:page>

Hope this helps ! Mark it as solved if it did.

Thanks,
Sarvani
Raj VakatiRaj Vakati
You have to add all the required fields on the above code ..I guess that wont work .. you need to use the apex class create an generate the Password... 


system.setpassword(UserID; Password) 

or use 
EmailHeader

 
Database.DMLOptions dlo = new Database.DMLOptions();

dlo.EmailHeader.triggerUserEmail= true;
 

 
Deepali KulshresthaDeepali Kulshrestha
Hi Dhilip,

Try the below code.

<apex:page standardController="Account">
  <apex:form>
    <apex:pageBlock title="My Content" mode="edit">
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="My Content Section" columns="2">
        <apex:inputField value="{!account.name}"/>
        <apex:inputField value="{!account.site}"/>
        <apex:inputField value="{!account.type}"/>
        <apex:inputField value="{!account.accountNumber}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Ajay K DubediAjay K Dubedi
Hi Dhilip,
You should use all mandatory field to create user. Please try the below code its works fine for me:
<apex:page standardController="user" >
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockSection >
        <apex:inputField value="{!user.FirstName}"/>
        <apex:inputField value="{!user.LastName}"/>
        <apex:inputField value="{!user.Email}"/>
        <apex:inputField value="{!user.ProfileId}"/>
        <apex:inputField value="{!user.UserName}"/>
        <apex:inputField value="{!user.Languagelocalekey}"/>
        <apex:inputField value="{!user.localesidkey}"/>
        <apex:inputField value="{!user.Timezonesidkey}"/>
        <apex:inputField value="{!user.Emailencodingkey}"/>
        <apex:inputField value="{!user.Alias}"/>
        <apex:inputField value="{!user.CommunityNickname}"/>
       </apex:pageBlockSection>
    </apex:pageBlock>
        <apex:commandButton value="save" action="{!save}"/>
    </apex:form>
</apex:page>
User-added image
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi