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
MY VF and ApexMY VF and Apex 

How to create UserRole with the help of vf page and apex class??

hi all,

can we create User role with the help of vf page and apex??

can we??

if yes then how??

 

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

You can use this

 

<apex:page StandardController="UserRole">
     <apex:form>
         <apex:pageBlock>
             <apex:pageblockButtons>
                 <apex:commandButton value="Save"  action="{!Save}"/>
             </apex:pageblockButtons>
             <apex:pageBlockSection>
                 <apex:inputField value="{!UserRole.Name}"/>
             
             </apex:pageBlockSection>
         
         </apex:pageBlock>
     
     </apex:form>
</apex:page>

 Add more field as per your need

 

See this for find fields which are creatable : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_role.htm

All Answers

Shashikant SharmaShashikant Sharma

You can use this

 

<apex:page StandardController="UserRole">
     <apex:form>
         <apex:pageBlock>
             <apex:pageblockButtons>
                 <apex:commandButton value="Save"  action="{!Save}"/>
             </apex:pageblockButtons>
             <apex:pageBlockSection>
                 <apex:inputField value="{!UserRole.Name}"/>
             
             </apex:pageBlockSection>
         
         </apex:pageBlock>
     
     </apex:form>
</apex:page>

 Add more field as per your need

 

See this for find fields which are creatable : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_role.htm

This was selected as the best answer
MY VF and ApexMY VF and Apex

Thanks Shashi....

but once we create user role with the help of this vf page...

then how to assign users to this particular role (because once we create new role after saving it goes to standard role detail page) can we cerate our vf detail page... and if yes then how to assign users through apex mechanism.

thank you once again.

MY VF and ApexMY VF and Apex

one more thing... u have seen that when we create new role at that time once we save we go to roles detail page...

from there we can assign users for that particular role...

one more button is there to create new user... i dont want this button... that is why i need to use vf and apex...

can i do this??

MY VF and ApexMY VF and Apex

i have created a userrole with the help of vf page.... i have created a vf page on which it will display all the list of Roles... i have also created a vf page as detail page of role...

but when I am clicking on particular role it shows error like this..

 

to create new user role

 

<apex:page standardController="UserRole">
   <apex:sectionHeader title="Role Creation"></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="Role Information" columns="2" collapsible="false"> 
                  <apex:inputField value="{!UserRole.Name}"/>
                  <apex:inputField value="{!UserRole.ContactAccessForAccountOwner}"/>
                  <apex:inputField value="{!UserRole.CaseAccessForAccountOwner}"/>
                  <apex:inputField value="{!UserRole.ForecastUserId}"/>
                 
                 
                 
                
                  <apex:inputField value="{!UserRole.PortalRole}"/>
                  <apex:inputField value="{!UserRole.PortalType}"/>
                  <apex:inputField value="{!UserRole.RollupDescription}"/>
                 
                 
                 
             
              </apex:pageBlockSection>
             
              </apex:pageBlock>
              </apex:form>
</apex:page>

 

detail of Userrole

 

<apex:page standardController="UserRole" tabStyle="Admin__c">
    <apex:detail title="true" relatedList="true"/>
</apex:page>

 

Error is-:

 

An internal server error has occurred An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.

Thank you again for your patience and assistance. And thanks for using salesforce.com!

Error ID: 498655240-27989 (-845424718)