You need to sign in to do that
Don't have an account?

Override Contact Lookup with Visualforce page
Hi again all, I have been experimenting with Jeff Douglas' "Roll your own Salesforce popup window,"
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
I have configured it successfully with the contact object in mind, customizing the code to enable it to work with the contact object, having the ability to create records within the vf page. Everything works well.
A couple of questions I am wondering about expanding its implementation and expansion. I will include the current code, I have below.
1. One of the things, I am attempting to determine is if it is possible to override the current contact quick create/lookup page. When a user clicks the magnifying glass on a certain object, are they then able to taken to the corresponding visualforce. I've heard historically, this may not be possible, so I'll understand if that is the case. But if so, what are the best methods to implement.
2. More so, I am working on an application that will be utilizing such a lookup, I am wondering if there is a way to incorporate as a visualpage within the object or a field to essentially update the related contact lookup field within the object.
Many thanks for all your help.
VF PAGE
Apex Class
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
I have configured it successfully with the contact object in mind, customizing the code to enable it to work with the contact object, having the ability to create records within the vf page. Everything works well.
A couple of questions I am wondering about expanding its implementation and expansion. I will include the current code, I have below.
1. One of the things, I am attempting to determine is if it is possible to override the current contact quick create/lookup page. When a user clicks the magnifying glass on a certain object, are they then able to taken to the corresponding visualforce. I've heard historically, this may not be possible, so I'll understand if that is the case. But if so, what are the best methods to implement.
2. More so, I am working on an application that will be utilizing such a lookup, I am wondering if there is a way to incorporate as a visualpage within the object or a field to essentially update the related contact lookup field within the object.
Many thanks for all your help.
VF PAGE
<apex:page controller="ContactLookupControl" title="Search" showHeader="false" sideBar="false" tabStyle="Contact" id="pg"> <apex:form > <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel"> <!-- SEARCH TAB --> <apex:tab label="Search" name="tab1" id="tabOne"> <apex:actionRegion > <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/> <apex:inputText id="txtSearch" value="{!searchString}" /> <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span> </apex:outputPanel> <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block"> <apex:pageBlock id="searchResults"> <apex:pageBlockTable value="{!results}" var="a" id="tblResults"> <apex:column > <apex:facet name="header"> <apex:outputPanel >Name</apex:outputPanel> </apex:facet> <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink> </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Account Name</apex:outputPanel> </apex:facet> {!a.Account.Name} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Street</apex:outputPanel> </apex:facet> {!a.MailingStreet} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >City</apex:outputPanel> </apex:facet> {!a.MailingCity} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >State</apex:outputPanel> </apex:facet> {!a.MailingState} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Postal Code</apex:outputPanel> </apex:facet> {!a.MailingPostalCode} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Phone</apex:outputPanel> </apex:facet> {!a.Phone} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Email</apex:outputPanel> </apex:facet> {!a.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:actionRegion> </apex:tab> <!-- NEW CONTACT TAB --> <apex:tab label="New Contact" name="tab2" id="tabTwo"> <apex:pageBlock id="newContact" title="New Contact" > <apex:pageBlockButtons > <apex:commandButton action="{!saveContact}" value="Save"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection columns="2"> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField value="{!Contact.LastName}"/> <apex:inputField value="{!Contact.AccountId}"/> <apex:inputField value="{!Contact.MailingStreet}"/> <apex:inputField value="{!Contact.MailingCity}"/> <apex:inputField value="{!Contact.MailingState}"/> <apex:inputField value="{!Contact.MailingPostalCode}"/> <apex:inputField value="{!Contact.MailingCountry}"/> <apex:inputField value="{!Contact.Phone}"/> <apex:inputField value="{!Contact.Email}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page>
Apex Class
public class ContactLookupControl { public Contact contact {get;set;} // new contact to create public List<Contact> results{get;set;} // search results public string searchString{get;set;} // search keyword public ContactLookupControl() { contact = new Contact(); // get the current search string searchString = System.currentPageReference().getParameters().get('lksrch'); runSearch(); } // performs the keyword search public PageReference search() { runSearch(); return null; } // prepare the query and issue the search command private void runSearch() { // TODO prepare query string for complex serarches & prevent injections results = performSearch(searchString); } // run the search and return the records found. private List<Contact> performSearch(string searchString) { String soql = 'select id, name,account.Name,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact'; if(searchString != '' && searchString != null) soql = soql + ' where name LIKE \'%' + searchString +'%\''; soql = soql + ' limit 25'; System.debug(soql); return database.query(soql); } // save the new contact record public PageReference saveContact() { insert contact; // reset the contact contact = new Contact(); return null; } // used by the visualforce page to send the link to the right dom element public string getFormTag() { return System.currentPageReference().getParameters().get('frm'); } // used by the visualforce page to send the link to the right dom element for the text box public string getTextBox() { return System.currentPageReference().getParameters().get('txt'); } }