• Medhanie Habte
  • NEWBIE
  • 125 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 17
    Replies
Hi all,

I have a formula field that I built in a custom object that combines various fields into this one field for a mail merge. The custom object is called Product Donations, and there are about 12 fields referencing various line items that are referenced here. 
 
SUBSTITUTE( 
IF(ISBLANK(NEW_Letters__c),"", Letter_Count__c) 
&IF(ISBLANK(Gators__c),""," "&TEXT(Gators__c) & " handmade gators,") 
&IF(ISBLANK(Paracords__c),"", " "&TEXT(Paracords__c) & " paracord bracelets,") 
&IF(ISBLANK(Cool_Ties__c),"", " "&TEXT(Cool_Ties__c) & " handmade cool ties,") 
&IF(ISBLANK(Phone_Cards__c),"", " "&TEXT(Phone_Cards__c) & " phone cards,") 
&IF(ISBLANK(Battalion_Buddy__c),"", " "&TEXT(Battalion_Buddy__c) & " battalion buddies,") 
&IF(ISBLANK(Comic_Books__c),"", " comic books,") 
&IF(ISBLANK(Magazines__c),"", " magazines,") 
&IF(ISBLANK(Books__c),"", " books,") 
&IF(ISBLANK(Handmade_Cards__c),"", " handmade cards,") 
&IF(ISBLANK(Care_Kits__c),""," care kits,") 
&IF(ISBLANK(Gift_Cards__c),""," gift cards,") 
&IF(ISBLANK(Socks__c),"", " socks,") 
&IF(ISBLANK(Girl_Scout_Cookies__c),"", " "&TEXT(Girl_Scout_Cookies__c) & " boxes of Girl Scout cookies,") 
&IF(ISBLANK(Food_And_Snacks__c),"", " snack foods,") 
&IF(ISBLANK(Toys_Animals_Bears__c),""," assorted toys,") 
&IF(ISBLANK(Beanie_Babies__c),"", " "&TEXT(Beanie_Babies__c)& " Beanie Babies,") 
&IF(ISBLANK(Hats__c),"", " "&TEXT(Hats__c) & " handmade hats," ) 
&IF(ISBLANK(Scarves__c),"", " "&TEXT(Scarves__c)& " handmade scarves,") 
&IF(ISBLANK(Video_Games__c),"", " "&TEXT(Video_Games__c)& " video games,") 
&IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(CDs_DVDs__c)& " CD's,") 
&IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(DVDs__c)& " DVD's,") 
&IF(ISBLANK(Candy_lbs__c),"", " "&TEXT(Candy_lbs__c)& " Lbs of candy,") 
&IF(ISBLANK(Assorted_Items__c),""," assorted items,") 
&IF(ISBLANK(Recyclables__c),"", " recyclable items,")& " ", 

",.", 

"" 
)

On the letter count, if there are additional itmes, I notice that a comma does not appear after it, it reads for example letters 1 scarves, 20 paracords, assorted items. Additionally, I am also looking for a way to include the word "and" after the comma if multiple line items exist. In this case, it should read as

letters 1 scarves, 20 paracords and assorted items.

Instead of 

letters 1 scarves, 20 paracords, assorted items

Also is there a formula to singularize items that have a 1 in it. For instance 1 scarves should just say scarf.

I can help with any further questions, even set up a trigger if needed. 

Hope this helps.
Greetings, I am looking to create a formula field that compares data values. In the event that the dates don't match up. If they don't I want to create that refers the date in the account field if it is less than that in the contact field, and vice versa. 
 
IF(npo02__FirstCloseDate__c <> Account.npe01__FirstDonationDate__c,
IF(npo02__FirstCloseDate__c < Account.npe01__FirstDonationDate__c, npo02__FirstCloseDate__c,
IF(npo02__FirstCloseDate__c > Account.npe01__FirstDonationDate__c, Account.npe01__FirstDonationDate__c
,npo02__FirstCloseDate__c
)))
However, I get this error message reading Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 2.

Any thing I'm missing. Hope it helps.
 
Greetings I am looking to create a fromula field that populates data according to these two if statements for my opportunity field. This field will be referenced a mail merge document. Basically if the account and contact full name don't match and the contact/donor record type is not in individual, then a text result will populate as this is a person account, otherwise, it will just say dear so and so.

IF(Account.Name <> Contact.Full_Name__c) and IF(Donor_Type__c !="Individual") then Product_Donations_Summary__c = "Greetings from Us", Dear+Contact.First_Name__c

Hope it helps.
Greetings, I am looking to drafta a concatenated formula field that would sort values in descending order, where the highest value referencing field appears first and so on and so forth. I have my code designed as such, but am stuck with how to reference the fields. Are there any steps I can take or ideas I should consider. Hope it helps.
 
trigger ProductDonationsSummary on Product_Donations__c (before insert) 
{
   
Map<Integer, String> mapNumValueAndFieldLabel = new Map<Integer,String>();
String strMessage;

//null checkers for the field and adding the number value as key and the string message as the value if its not null/blank/zero
IF(Total_LettersTally__c != null && Total_LettersTally__c != '' && Integer.valueOf(Total_LettersTally__c) != 0)
    mapNumValueAndFieldLabel.put(Integer.valueOf(Total_LettersTally__c), Total_LettersTally__c + " letters");

IF(Gators__c != null && Gators__c != '' && Integer.valueOf(Gators__c) != 0)
    mapNumValueAndFieldLabel.put(Integer.valueOf(Gators__c), Gators__c + " Gators");

IF(Paracords__c != null && Paracords__c != '' && Integer.valueOf(Paracords__c) != 0)
    mapNumValueAndFieldLabel.put(Integer.valueOf(Paracords__c), Paracords__c + " paracord bracelets");

//and so on for other fields....

//Proceed further only if either of the fields have non zero values 
if(mapNumValueAndFieldLabel.values().size() > 0)
{
    List<Integer> lstNumValue = new List<integer> ();
    lstNumValue.addAll(mapNumValueAndFieldLabel.keyset());

    //Sort the Values (by default SFDC sorts it in ascending order)
    lstNumValue.sort();

    //Iterating through the sorted Integer list in reverse order (descending) to get the final String message from the map 
    for(Integer i = lstNumValue.size()-1; i >= 0; i--)
    {
        strMessage = mapNumValueAndFieldLabel.get(lstNumValue(i)) + ", ";
    }
}

//strMessage will hold the message you want to display

}



 
Greetings, I've been working with Jeff Douglas' Roll Your Salesforce Lookup (http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/) as part of an app I've been building in our org. This app serves to replace the dreaded quickcreate system and allows for the inline creation of contact records, should they not be available.

One of the initial issue we have encountered is the inability to look up or add contact records with quotes (') in their first or last name as part of the query. This returns an exception error. A step I took to address was to escapesinglequote, which allows for looking up contacts with ('). Now with Single Quote escaped, I am unable to close the popup when I create new records or select a record with a (') in the result. I'm certain this may have to do with the code in the VF page. I am wondering what steps I need to take.

Are there any steps, I can take to address. Class and Page attached below.

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;
    contact=[select id,name,FirstName,LastName,AccountId,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact where id=:contact.id];
    // 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');
  }
  }




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);self.close();" 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 & Close"/>
          </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>   
        <script>
        if({!Contact.id!=null}){
            //alert('{!Contact.Name} {!Contact.id}');
            top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!Contact.Id}','{!Contact.Name}', false);self.close();
        }
        </script>
    </apex:tab>
  </apex:tabPanel>
  </apex:outputPanel>
  </apex:form>
</apex:page>

Hope it helps.
Greetings,

I am trying to figure out a way to update the opportunity amount field to match a custom currency field that updates when a payment is made. My goal is for the amount field to match up with the custom currency (basically watching the field for any changes) and this would be contingent on if the recurring payment picklist field is set to recurring and the subscription end date is not greater than or does not equal TODAY. It would process on update.

I have attempted to do this via workflow, but this does not process during an APEX batch as the value is considered NULL. Any steps I can take. I trust this helps. I'll be looking around for ideas too.
Hello,

I'm pretty new to salesforce and formulas so forgive me if I'm missing something obvious. I'm trying to use a formula that will allow me to run reports on accounts sorted by their time zone. This is my formula:

IF(CASE(State, “California”, 1, “Nevada”, 1, “Oregon”, 1, “Washington”, 1, 0) >=1, “Pacific”, null)+
IF(CASE(State, “Arizona”, 1, “Colorado”, 1, “Idaho, 1, “Montana”, 1, “New Mexico”, 1, “Utah”, 1, “Wyoming”, 1, 0) >= 1, “Mountain”, null)+
IF(CASE(State, “Alabama”, 1, “Arkansas”, 1, “Illinois”, 1, “Iowa”, 1, “Kansas”, 1, “Louisiana”, 1, “Minnesota”, 1, “Mississippi”, 1, “Missouri”, 1, “Nebraska”, 1, “North Dakota”, 1, “Oklahoma”, 1, “South Dakota”, 1, “Tennessee”, 1, “Texas”, 1, “Wisconsin”, 1, 0) >= 1, “Central”, null)+
IF(CASE(State, “Connecticut”, 1, “Delaware”, 1, “Florida”, 1, “Georgia”, 1, “Indiana”, 1, “Kentucky”, 1, “Maine”, 1, “Maryland”, 1, “Massachusetts”, 1, “Michigan”, 1, “New Hampshire”, 1, “New Jersey”, 1, “New York”, 1, “North Carolina”, 1, “Ohio”, 1, “Pennsylvania”, 1, “Rhode Island”, 1, “South Carolina”, 1, “Vermont”, 1, “Virginia”, 1, “West Virginia”, 1, 0) >= 1,”Eastern”, null)+
IF(CASE(State, “Alaska”, 1, 0) >=1, “Alaskan”, null)+
IF(CASE(State, “Hawaii”, 1, 0) >=1, “Hawaiian”, null)+
IF(CASE(BillingState, “California”, 1, “Nevada”, 1, “Oregon”, 1, “Washington”, 1, “CA”, 1, “NV”, 1,”OR”, 1, “WA”, 1, 0) >=1, “Pacific”, null)+
IF(CASE(BillingState, “Arizona”, 1, “Colorado”, 1, “Idaho, 1, “Montana”, 1, “New Mexico”, 1, “Utah”, 1, “Wyoming”, 1,“AZ”, 1, “CO”, 1,”ID”, 1, “MT”, 1, “NM”, 1, “UT”, 1, “WY”, 1, 0) >= 1, “Mountain”, null)+
IF(CASE(BillingState, “Alabama”, 1, “Arkansas”, 1, “Illinois”, 1, “Iowa”, 1, “Kansas”, 1, “Louisiana”, 1, “Minnesota”, 1, “Mississippi”, 1, “Missouri”, 1, “Nebraska”, 1, “North Dakota”, 1, “Oklahoma”, 1, “South Dakota”, 1, “Tennessee”, 1, “Texas”, 1, “Wisconsin”, 1, “AL”, 1, “AR”, 1, “IL”, 1, “IA”, 1,”KS”, 1, “LA”, 1,”MN”, 1,”MS”, 1,”MO”, 1,”NE”, 1,”ND”, 1, “OK”, 1,”SD”, 1, “TN”, 1, “TX”, 1,”WI”, 1, 0) >= 1, “Central”, null)+
IF(CASE(BillingState, “Connecticut”, 1, “Delaware”, 1, “Florida”, 1, “Georgia”, 1, “Indiana”, 1, “Kentucky”, 1, “Maine”, 1, “Maryland”, 1, “Massachusetts”, 1, “Michigan”, 1, “New Hampshire”, 1, “New Jersey”, 1, “New York”, 1, “North Carolina”, 1, “Ohio”, 1, “Pennsylvania”, 1, “Rhode Island”, 1, “South Carolina”, 1, “Vermont”, 1, “Virginia”, 1, “West Virginia”, 1, “CT”, 1, “DE”, 1, “FL”, 1,“GA”, 1, “IN”, 1, “KY”, 1,“ME”, 1, “MD”, 1, “MA”, 1,”MI”, 1, “NH”, 1, “NJ”, 1, “NY”, 1, “NC”, 1, “OH”, 1, “PA”, 1, “RI”, 1, “SC”, 1, “VT”, 1, “VA”, 1, “WV”, 1, 0) >= 1,”Eastern”, null)+
IF(CASE(BillingState, “Alaska”, 1,“AK”, 1, 0) >=1, “Alaskan”, null)+
IF(CASE(BillingState, “Hawaii”, 1,“HI”, 1, 0) >=1, “Hawaiian”, null)+

I keep running into a syntax error when I test it. It highlights "California",
 User-added image


Is my formula incorrect? What am I doing incorrectly?

Regards,
Jeff
Greetings, I have a formula field in my Salesforce instance that concatenates the contact records first and last names FirstName & LastName. Some of my contacts do not have first names, in the full name formula both fields are taken into account and thus a contact with a last name in this field would appear as " Friend" rather than "Friend." I am wondering if there is a solution to trim the first space in the field.

Hope it helps.
I am looking to reformat a formula field I've created for a custom object. This formula field, disambiguates between the account object and contact object, as we are on the one-to-one relationship model in Salesforce, in which a contact that is an individual is both contact/account and a contact representing a company is a group.

Currently my formula for the field is configured this way, I've created a concatenated formula in contact object which takes the first and last name and merges it into one. For instance First Name: Joe Last Name: Smith = Joe Smith

For the custom Object I've designed this formula in the field

IF(Account__r.Name = Contact__r.FullName__c , NULL,"Attn: " & Contact__r.FirstName & Contact__r.FullName__c)

However, at times, when I only input the last name and leave the first name field blank, in the instance that the contact does not have the first name, the Attention to formula returns a value when it should be blank.

Are there any customizations, I can make to my formula to make it so that even without the first name filled, it only returns when the account name and contact name do not match. IE Account Name SampleCO, Contact Joe Smith

Account                               Contact                                     Attention to

User-added image
Greetings all, I am running into the Too Many SOQL queries issue when running a test for this apex class. The testregistrations component passes but the mypage_test fails.

Any thing, I may need to adjust here.
 
public class eventsControllerTests {

static testMethod void myPage_Test()
  {
  //Test converage for the myPage visualforce page
  PageReference pageRef = Page.Events_Home;
  Test.setCurrentPageReference(pageRef);
  // create an instance of the controller
  eventsController myPageCon = new eventsController();
  //try calling methods/properties of the controller in all possible scenarios to get the best coverage.

  myPageCon.Setup();
  String efSetupPage = myPageCon.Setup().getUrl();
  System.assertEquals('/apex/EventsSuccess',efSetupPage);

  myPageCon.closePopupOK();

  }
  
    static testMethod void testRegistrationsTrigger(){
        
        //First, prepare 200 contacts for the test data
        
        String contactLastName = 'Apex';
        String contactFirstName = 'Joe';
        String contactTitle = 'Manager';
        Contact ct = new Contact(lastname=contactLastName, firstname=contactFirstName, title=contactTitle);
        insert ct;
        
        ct = [SELECT Name, Title from Contact WHERE Id = :ct.Id];
        
        Event__c ev = new Event__c(name = 'My Event');
        insert ev;

        Event_Registration__c reg = new Event_Registration__c(Contact__c=ct.Id,Event__c=ev.Id);
        insert reg;

        reg = [SELECT Name_on_Badge__c, Title_On_Badge__c from Event_Registration__c WHERE Id = :reg.Id];
        System.assertEquals(ct.Name, reg.Name_on_Badge__c);
        System.assertEquals(ct.Title, reg.Title_on_Badge__c);

           
    }   
}

 
I am conducting an Apex test for ChatterAnswersAuthProviderRegTest, as I run this test, I encounter the following error message.

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]

I am curious to know where to go about obtaining the the id of a Chatter Answers Profile. I have attempted to call ProfileId though it appears the profile Id's I have available do not seem to allow. Or any steps I need to take.
 
@isTest(SeeAllData=True)
private class ChatterAnswersAuthProviderRegTest {
    static testMethod void validateCreateUpdateUser() {
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs ( thisUser ) {
            Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast',
            'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
            null, new Map<String, String>{'language' => 'en_US'});
            ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration();
            Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
            User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1];
            reg.setSiteAdminUserId(adminUser[0].Id);
            User newUser = reg.createUser(null, userData);
            System.assert(newUser != null, 'A new user should have been created');
            System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same');
            System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same');
            System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same');
            
            Contact c = new Contact();
            c.AccountId = (newUser.Username.split('@'))[0];
            c.LastName = 'contactLast';
            insert(c);
            
            newUser.Alias = 'firstusr';
            newUser.TimeZoneSidKey = 'America/Los_Angeles';
            newUser.LocaleSidKey = 'en_US';
            newUser.EmailEncodingKey = 'UTF-8';
            newUser.LanguageLocaleKey = 'en_US';
            newUser.ContactId = c.Id;
            
            insert(newUser);
            
            
            Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast',
            'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
            null, new Map<String, String>{'language' => 'en_US'});
            reg.updateUser(newUser.Id, null, updateUserData);
            
            User dbUser =  [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id];
            System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated');
            System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated');
            System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated');
        }
    }
}

 
Greetings, I currently only am able to achieve anywhere between 16-34% coverage with my current apex test class and am trying to determine ways to improve my apex class coverage.


Here is an instance of my apex class itself
 

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 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');
  }

}


Here's the test class too

TEST CLASS

@isTest 
public class ContactLookupControlTest {
    static testMethod void validateContactLookupControl() {
        Contact c = new Contact();
            c.FirstName = 'Paul';
            c.LastName = 'Reid';
            c.MailingStreet = '205 Hill Street';
            c.MailingCity = 'Los Angeles';
            c.MailingState = 'CA';
            c.MailingPostalCode = '90015';
            c.Email = 'testingout1@aol.com';
            insert c;
    }
}

Are there any additional steps I can pursue to enable it to work accordingly. Let me know and hope it helps.