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
Anilkumar458Anilkumar458 

wheather its possible to create user using controller extension using own save method

Hello All,

 

whether its possible to ctrate user using custom pages and controller extensions using own save method?

 

Regards

Anilkumar

HarmpieHarmpie

Yes. Quick example:

 

Page:

<apex:page standardController="Account" extensions="MyExt"> <apex:pageBlock> <apex:pageBlockButtons> <apex:commandButton value="Overridden save" action="{!mySaveOverride}" /> <apex:commandButton value="Normal save" action="{!save}" /> </apex:pageBlockButtons> <!-- REST OF PAGE HERE--> </apex:pageBlock> </apex:page>

 

Controller extension

 

public class MyExt { public Account acct { get;set; } public ApexPages.StandardController controller { get;set; } public MyExt(ApexPages.StandardController stdController) { this.controller = stdController; this.acct = (Account)stdController.getRecord(); } public PageReference mySaveOverride() { // do something here // and then call : return this.controller.save(); // or do something like update acct, after doing your logic, // in that case, end with: return this.controller.view(); // or another valid page reference } }

 

Anilkumar458Anilkumar458

hi ,

i have written the controller using user as u said.but for my case it is not storing the records.I dont know why .Could you help me if posible....

 

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> 


My Apex class:


public class usercontroller {

 

public User cntr{
        get;set;
    }

 

    public usercontroller(ApexPages.StandardSetController controller) {
   
   

    }

 public ApexPages.StandardController controller {
        get;set;
    }


 //
    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()
  
     {
     
         
          this.controller.save();


     
                
        PageReference pageRef = new  PageReference('https://c.na6.visual.force.com/apex/users');
          pageRef.setRedirect(true);
         return pageRef ;
      
      
    } 

 

}


 

 

 

Devendra SawantDevendra Sawant

Hi,

 

I am facing the same problem.

 

Have you got the answer for this??

 

Please let me know.

 

Cheers,

Devendra S