+ Start a Discussion
SuriSuri 

User Role Lookup issue!

Hi all,
 
Any thoughts on why this happens?
 
Basically, I have a user Object defined in my Controller, and there are 2 input Fields on my VF page.
 
The inputFields are: User.UserRoleId and User.ProfileId
 
When the Role Lookup is selected, and if ANY action happens on the page, the Role simply disappears i.e., becomes null.
 
Any clue why? Or is it a bug in salesforce.com?

 
Please have a look at the code below. Paste this, and just select a Role and hit the "Test" button.
 
VF Page Markup:

======================= VF PAGE MARK UP ==============================
<apex:page controller="TempRolePageController">
<apex:form >
    
    <apex:pageBlock >
        
        <apex:pageBlockButtons >
            <apex:commandButton value="Test" action="{!testButton}" />
        </apex:pageBlockButtons>
        
        <apex:pageBlockSection >
        
            <apex:inputField value="{!userObj.UserRoleId}" required="false" />
            
            <apex:inputField value="{!userObj.ProfileId}" required="false" />
        
        </apex:pageBlockSection>
        
    </apex:pageBlock>
    
    SELECTED ROLE ID: {!userObj.UserRoleId} <br/><br/>
    SELECTED PROFILE ID: {!userObj.ProfileId}
</apex:form>
</apex:page>

=====================================================================
 
Apex Class:
 
==================== CONTROLLER =====================================
 
public class TempRolePageController {

    

    public User userObj { get; set; }

    

    public TempRolePageController()

    {

        userObj = new User();

    }

    

    //Test button

    public pageReference testButton()

    {

        return null;

    }

    



}

=======================================================================

WesNolte__cWesNolte__c

Hey

 

You're looking up values on an empty user, that's why your values are null. What is this form going to do, create users? Edit users?

 

Wes

SuriSuri

Hi

 

My purpose is to have an exclusive Roles Lookup on a page to store the selected Role ID somewhere.

 

Yes I know its an empty User, but My question here is very simple:

 

Why does the inputField User.UserRoleId disappear while the User.ProfileId remains?

 

Both are inputFields, and the value is to be retained.

WesNolte__cWesNolte__c

You're right, that is a very simple question, but it can have a number of answers. When you an action occurs you'll notice your page refreshes, and controller values should be retained. Something is amiss here, but you can solve the problem by using a rerender:

 

 

<apex:page controller="TempRolePageController">
<apex:form >
    
    <apex:pageBlock >
        
        <apex:pageBlockButtons >
            <apex:commandButton value="Test" action="{!testButton}" rerender="mypanel"/>
        </apex:pageBlockButtons>
        
        <apex:pageBlockSection >
        
            <apex:inputField value="{!userObj.UserRoleId}" required="false" />
            
            <apex:inputField value="{!userObj.ProfileId}" required="false" />
        
        </apex:pageBlockSection>
        
    </apex:pageBlock>
    
    <apex:outputPanel id="mypanel">
    SELECTED ROLE ID: {!userObj.UserRoleId} <br/><br/>
    SELECTED PROFILE ID: {!userObj.ProfileId}
    </apex:outputPanel>
</apex:form> 
</apex:page>

 

Or if that isn't an option, let me know, there are a number of other options such as using standardcontroller or controller extensions, but this is probabaly the simplest it'll get.

 

Wes

 

 

 

SuriSuri

Hi,

 

Thanks a lot. But yes, I'm aware of the reRender attribute.

 

The page refreshes, but the Controller values are retained, and the constructor is not called again.

 

And yes I've been working with Apex and Visualforce for the past 20months and I'm well aware of the StandardController / Extensions too.

 

But this is something weird happening specifically to the Role Lookup.

 

Because in my page, logically of the User.ProfileId value is retained, so should the User.UserRoleId value.

 

I also tried declaring a UserRole object, and used the "{!UserRole.ParentRoleId}" as an input Field.

 

This is also a Role Lookup, and the same disappearing happens.

 

I've tried out all possible trouble-shooting and posted this on the community as a last resort. :)

WesNolte__cWesNolte__c

In Salesforce terms that makes you a Senior Developer ;)

 

It's most likely a bug, and you should open a case.

 

Wes

SuriSuri

he.. he.. Thanks.. :)

 

Yes, I have just logged a Case to Salesforce, and hoping I'll get a reply soon. <fingers crossed>