1

enter image description hereI want to create a VF page where I can render a lookup field to profile.

This is what I have done till now. AdminController is my Custom Controller

public with sharing class AdminController{

   public User user1 {get;set;}

   public AdminController(){

      user1=new User();
   }
}

Now in VF page

<apex:inputField value="{!user1.Profile}" />

But I am getting Error :

Expression value does not resolve to a field Error is in expression '{!user1.Profile}' in component in page

1 Answer 1

1

Unfortunately for the profile you wont be able access as a lookup as we all know there is no such field in salesforce thats lookup to profile

The alternative solution could be to roll your own custom lookup window as shown in below blog

http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/

OR just think of a new window open in javascript and pass the value from child window to the parent window .

Lets say i want to open a visualforce page(PageOpener) as a pop up window through a sample vf page named WindowOpenerTest

Code for the WindowOpenerTest(Parent page)

<apex:page id="page">
<apex:form id="theform">
    <script type="text/javascript">
             var newWin;

 function openWin(){
    var url="/apex/PageOpener";
    newWin=window.open(url, 'Popup','height=500,width=800,left=200,top=100');
    newWin.focus();
} 

 function parentalert(camp){
     document.getElementById('{!$Component.hello}').value=camp;
     //alert(a);
//alert('In parent Window<<<<<<<'+camp);
  newWin.close();
}


 </script>
      <apex:inputText id="hello" onclick="openWin();" />
    </apex:form>
    </apex:page>

Code for the child window(PageOpener) and script for the communication from child to parent window

<apex:page sidebar="false" showHeader="false">

<apex:form >
    <!-- Begin Default Content REMOVE THIS -->
    <h1>Congratulations</h1>
            This is your new Page
            <!-- End Default Content REMOVE THIS -->

    <apex:outputLink id="theLink"
        onclick="sendPopUpValues('{!$User.Alias}')" styleClass="p"> Link
                 </apex:outputLink>

    <script type="text/javascript">
         function sendPopUpValues(camp){//sending user Alias to the parent window through script
            window.opener.parentalert(camp);
   }        
   </script>

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

The above code should get you started and help you on how to send values between parent and child windows.

5
  • @MohitKumar : I have checked in User object, I found there is a standard field named 'Profile' which has a lookup relationship to profile. can't we use that field?? Correct me If I'm wrong Commented Nov 18, 2013 at 9:49
  • iTS NOT lookup right ?Its picklist ? Commented Nov 18, 2013 at 9:58
  • @MohitKumar : I have added snapshot in my main question. Commented Nov 18, 2013 at 10:06
  • Its picklist .Its never lookup and hence you may need to roll your own window Commented Nov 18, 2013 at 10:08
  • I'm missing where in the code the id is updated. It seems to me there are two fields that need to be updated, what the user sees (typically the name) and the actual 18-character id. Where does that happen?
    – tggagne
    Commented Apr 28, 2014 at 11:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .