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
Priyanka PallepatiPriyanka Pallepati 

Look up field on VF Page

Hi,

I have a look up field on visual force page. Need a look up to user. So querying contact by logged in user and making use of contact.reportsId as the value of input field. This is bringing up the look up field to user and wanted the input field before the glass icon to be disabled. so I did this way. 
  • <apex:inputField id="requestor" value="{!contact.ReportsToId}"  html-disabled="true">
I also have a button besides the input field as below 
  • <apex:commandButton value="Submit" action="{!doSave}"/>
so whenever a user picks up a user by the glass icon and clicks on submit, I want the text of value sent to my controller in doSave method.
For example: if I pick Priyanka Pallepati as the user by clicking the glass icon of look up field, I want to send Priyanka Pallepati to my doSave method.

How do I achieve this? Any suggestions would be highly appreciated.

Regards,
Priyanka.
Best Answer chosen by Priyanka Pallepati
Neetu_BansalNeetu_Bansal
Hi Priyanka,

This is impossible, in the con.ReportsToId, you must be getting a contact Id and if you query on contact with that id, it must return the record. Check my code, in the where clause I am comparing
where Id =: con.reportsToId
 and I think your query is like
where reportsToId =: con.reportsToId
the later will not return any record, beacuse as you checked all the contacts in your org have reportsToId as null. If you still faces the issue, either provide me your org credentials or contact me on my email Id: neetu.bansal.5@gmail.com

Thanks,
Neetu

All Answers

Priyanka PallepatiPriyanka Pallepati
The only catch that I found was that since the input field is disabled before the glass icon, none of the actions are working. Like action support. also any java script functions on actions. May be I am not doing it right? Not sure. Please help.
Neetu_BansalNeetu_Bansal
Hi Priyanka,

As you have binded the look up with the contact.ReportsToId, so in your doSave method, use it directly, as it is binded already with the controller and you don't need to pass it to controller. Like:
public class Test
{
	public Contact con { get; set; }
	
	public void doSave()
	{
		cont.ReportsToId // Use this value, as it is already binded with the controller.
	}
}
If it doesn't help, paste the code of your page and class.

If this post helps you, mark it as best answer, so will help others in future.

Thanks,
Neetu
Priyanka PallepatiPriyanka Pallepati
Hi Neetu,

I got the reportsToId in my controller.. But if I query contact by its reportsToId I get no returned contacts. I queried in salesforce schema, all the contacts in org dont have reportsToId.
All I need is a look up to Contact and when they pick a contact I should be able to query the contact by the value.

Can you help?

Thanks,
Priyanka
 
Neetu_BansalNeetu_Bansal
Hi Priyanka,

So your requirement is there is a look up of contact, as the user picks the contact, you want to query that contact. is it?
If yes, then while querying, search in contact id, not in reportsToId, as you want to search all contact like:
public class Test
{
	public Contact con { get; set; }
	
	public void doSave()
	{
		List<Contact> contacts = [ Select Id, Name from Contact where Id =: con.reportsToId ]; // This will give you the contact which was selected by user.
	}
}

If it still doesn't help, paste the code of your page and class.

If this post helps you, mark it as best answer, so will help others in future.

Thanks,
Neetu
 
Priyanka PallepatiPriyanka Pallepati
hi Neetu,

This is the same thing I tried. But I can't seem to query contact by its reportsToId.. list is coming as zero; I even went ahead and looked at eclipse salesforce schema queried all reportsToId for existing contact.. they seem empty..

thanks,
priyanka.
Neetu_BansalNeetu_Bansal
Hi Priyanka,

This is impossible, in the con.ReportsToId, you must be getting a contact Id and if you query on contact with that id, it must return the record. Check my code, in the where clause I am comparing
where Id =: con.reportsToId
 and I think your query is like
where reportsToId =: con.reportsToId
the later will not return any record, beacuse as you checked all the contacts in your org have reportsToId as null. If you still faces the issue, either provide me your org credentials or contact me on my email Id: neetu.bansal.5@gmail.com

Thanks,
Neetu
This was selected as the best answer