+ Start a Discussion
KbhaskarKbhaskar 

Standard Object Permissions via custom visualfroce page

Hi,
According to a requirement ,I have created a vf page to create a user but on same time Standard Object Permissions should be editied on the same visualfroce page and it should be reflected to the desired profile is it possible ?
 
<apex:page standardController="User" extensions="CreateNewStaffAndUserExtension" >
 
 
   
  
<apex:sectionHeader title="Welcome" subtitle="Create a new user" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
    <apex:form >
        <apex:pageBlock mode="edit">
        <apex:pageMessages />
            <apex:pageBlockButtons >
                    <apex:commandButton action="{!save}" value=" Save " ></apex:commandButton>
                    <apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton>
                 </apex:pageBlockButtons>
              
              <apex:pageBlockSection title="User Information" columns="2" collapsible="false">  
                
                 
                  <apex:inputField value="{!User.IsActive}"/>
                  <apex:inputField value="{!User.FirstName}"/>
                  <apex:inputField value="{!User.Username}"/>
                  <apex:inputField value="{!User.LastName}"/>
                  <apex:inputField value="{!User.Email}"/>
                  <apex:inputField value="{!User.alias}"/>
                  <apex:inputField value="{!User.UserRoleId}"/>
                  
                 
                  </apex:pageBlockSection>
                 <!-- <apex:inputField value="{!User.UserType}"/> -->
            
           
            

              <!--  <apex:pageBlockSectionItem >
                    <apex:outputLabel value="User" for="usr"></apex:outputLabel>
                   
                    <apex:selectList value="{!selectedRoleId}" multiselect="false" size="1" id="selectedRoleId">
                       <apex:selectOptions value="{!userList}" />
                    </apex:selectList>
                    </apex:pageBlockSectionItem>
            
            -->
                    
                    
            <apex:pageBlockSection >
              <!--    <apex:inputField value="{!User.ProfileId}"/> -->
                   <apex:inputField value="{!User.Phone}"/>
                   <apex:inputField value="{!User.Extension}"/>
                   <apex:inputField value="{!User.Fax}"/>
                   <apex:inputField value="{!User.EmployeeNumber}"/>
                   <apex:inputField value="{!User.Title}"/>
                   <apex:inputField value="{!User.CompanyName}"/>
                   <apex:inputField value="{!User.Division}"/>
                   <apex:inputField value="{!User.Department}"/>
                   <apex:inputField value="{!User.CommunityNickName}"/>

                 <!--  <apex:inputField value="{!User.UserType}"/> -->
                   
                   <apex:inputField value="{!User.ReceivesInfoEmails}" />
                   </apex:pageBlocksection>
              
                    <apex:pageBlockSection columns="1" showHeader="false" title="License">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="License" for="lic"></apex:outputLabel>
                    <apex:selectList id="mgr" value="{!User.UserType}" size="1" title="Manager">
                        <apex:selectOptions value="{!license}"></apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Profile" for="pro"></apex:outputLabel>
                   
                    <apex:selectList value="{!User.ProfileId}" multiselect="false" size="1" id="selectedProfileId">
                       <apex:selectOptions value="{!profile}" />
                    </apex:selectList>
                    </apex:pageBlockSectionItem>
            </apex:pageBlockSection> 
            
              
              
               <apex:pageBlockSection title="Other Information" columns="1" collapsible="false">
                   <apex:inputField value="{!User.EmailEncodingKey}"/>
                   <apex:inputField value="{!User.TimeZoneSidKey}"/> 
                   <apex:inputField value="{!User.LocaleSidKey}"/>
                   <apex:inputField value="{!User.LanguageLocaleKey}"/>
               </apex:pageBlockSection>
            <apex:pageBlockSection>   
          <apex:pageBlockSectionItem >
          <apex:outputLabel value="License" for="lic"></apex:outputLabel>
          <apex:selectList id="mgr" value="{!User.UserType}" size="1" title="Manager">
             <apex:selectOptions value="{!license}"></apex:selectOptions>
            <u> <apex:actionSupport event="onchange" rerender="selectedProfileId"/></u>
           </apex:selectList>
        </apex:pageBlockSectionItem>
            
                       </apex:pageBlockSection>   

            
              </apex:pageBlock>
              </apex:form>
   </apex:page>

Apex class 
public class CreateNewStaffAndUserExtension {


   
    public Id accountId{get;set;}
    public String accountName{get;set;}

      public List<Account> accs{get;set;}

    private final User user;
    public CreateNewStaffAndUserExtension(ApexPages.StandardController controller)
    {
    
 
      this.user= (User)controller.getrecord();

    }
    
 
    public List<selectOption> getLicense()
    {
        List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
        options.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
          for (UserLicense users :[SELECT Id,Name FROM UserLicense])  
          {    
                options.add(new selectOption(users.Id, users.Name)); //for all records found - add them to the picklist options
          }
        return options; //return the picklist options
    }
    
    public List<selectOption> getProfile() {
        List<selectOption> options1 = new List<selectOption>(); //new list for holding all of the picklist options
        options1.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
     //   for (User users : [SELECT Id,UserType FROM User]) { //query for User records with System Admin profile
     for (Profile users1 :[SELECT Id,Name FROM Profile])  {    
                options1.add(new selectOption(users1.Id, users1.Name)); //for all records found - add them to the picklist options
        
        
        
        
        } 
        
        
        return options1; //return the picklist options 
   
   
    } 
  
    
 }


 
salesforce mesalesforce me
Hi...

           Yes its Possible we  can ...Give the permissions to the rest of users..through admin