Skip to main content
added 574 characters in body
Source Link
danielpm
  • 143
  • 1
  • 6
  • 16

The code is only implement to function with one objects, its only for example (City__c in this example).

EDIT: So, I have something like this:

Select List

I need this (the red square lookup button)

Lookup button

To open something like this

Lookup window

And populate the search field with the letters selected in the select list in the first image. I already tried to use the inputField but the salesforce gives me a error that says "inputField needs a sObject", and i'm out of ideas.

The code is only implement to function with one objects (City__c in this example).

The code is only implement to function with one objects, its only for example (City__c in this example).

EDIT: So, I have something like this:

Select List

I need this (the red square lookup button)

Lookup button

To open something like this

Lookup window

And populate the search field with the letters selected in the select list in the first image. I already tried to use the inputField but the salesforce gives me a error that says "inputField needs a sObject", and i'm out of ideas.

Source Link
danielpm
  • 143
  • 1
  • 6
  • 16

Lookup Window From SelectList Option

Here's the deal: I have a search field that searchs the object selected from the list, presenting the results below in a table. But in my next step, i want to add the lookup icon next to the text field opening a new windows to search and select (just like the Lookup API). I've already tried to change the inputText to inputField but it gives the error that "inputField can only be used with sObjects". I'm new to Salesforce and i've been trying find a sollution for hours already, so I need your help. Heres my page and my controller:

<apex:page standardController="Payment__c" extensions="PaymentExtension">
  <apex:form >
      <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                  <apex:pageBlockSectionItem >
                        <apex:selectList value="{!searchCategory}" size="1">
                              <apex:inputText value="{!searchCategory}"/>
                              <apex:selectOption itemValue="Country__c" itemlabel="Country"/>
                              <apex:selectOption itemValue="City__c" itemlabel="City"/>
                              <apex:selectOption itemValue="Town__c" itemlabel="Town"/>
                              </apex:selectList>
                  </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                  <apex:commandButton value="Search" action="{!find}" reRender="result"/>
            </apex:pageBlockButtons>
      </apex:pageBlock>
     
      <apex:pageBlock id="result" >
      <apex:pageBlockTable value="{!result}" var="res">
                  <apex:repeat value="{!objectFields}" var="field"> 
                        <apex:column value="{!res[field]}"/> 
                  </apex:repeat>
      </apex:pageBlockTable>       
      </apex:pageBlock>
</apex:form>
</apex:page>

Controller

public with sharing class PaymentExtension {
        public PaymentExtension(ApexPages.StandardController controller) {
    
        }
        
          public String searchKeyWord {get;set;}
          public String searchCategory {get;set;}
          public List<String> objectFields {get;set;}    
          public sObject sObjectToBind {get;set;}  
          public List<sObject> result {get;set;}
          
         
          public void Search()
          {
                searchCategory = 'Member__c';
          }
         
          public void find()
          {    
                /*    Getting fields for the sObject   */ 
            objectFields =  new List<String>();  
            Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();   
            Schema.sObjectType sObjType = globalDescription.get(searchCategory);             
            sObjectToBind = sObjType.newSObject();  
            Schema.DescribeSObjectResult r1 = sObjType.getDescribe();  
              
            Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();  
            for(Schema.SObjectField field : mapFieldList.values())  
            {  
                Schema.DescribeFieldResult fieldResult = field.getDescribe();  
                if(fieldResult.isAccessible())  
                {  
                    objectFields.add(fieldResult.getName());
                }  
            }  
           
            /*    Building Query with the fields    */
            /*Integer i = 0;
            String fieldsToFetch = '';
            for(String temp:objectFields)
            {       
                Integer len = objectFields.size();
                if(i==len-1)
                {
                      fieldsToFetch = fieldsToFetch + temp;
                }
                else
                {
                      fieldsToFetch = fieldsToFetch + temp + ',';
                }
                i++;
            }
                String sql = 'Select ' + fieldsToFetch + ' From ' + searchCategory + ' WHERE Name LIKE \'%' + searchKeyword + '%\'';
                result = Database.Query(sql);*/
                
                
                String fieldsToFetch = '';
                if (searchCategory == 'City__c') {
                    ObjectFields.clear();
                    ObjectFields.add('Name');
                    ObjectFields.add('Description__c');
                    ObjectFields.add('Country__c');
                    fieldsToFetch = 'Name,Description__c,Country__c';
                    String sql = 'Select ' + fieldsToFetch + ' From ' + searchCategory + ' WHERE Name LIKE \'%' + searchKeyword + '%\'';
                    system.debug(sql);
                    result = Database.Query(sql);
                    }
                    
                    system.debug(fieldsToFetch);
                    system.debug(searchCategory);
                    system.debug(searchKeyword);
                    system.debug(ObjectFields);
                
          }
         
          /*    Getting and Setting values for SearchCategory radio button    */
          public String getsearchCategory()
          {
                return searchCategory;
          }
         
          public void setsearchCategory(String searchCategory)
          {
                this.searchCategory = searchCategory;
          }
    
    }

The code is only implement to function with one objects (City__c in this example).

I already tried to implement a the new lookup window with the textField, but i failed, I'm out of ideas and can't find any useful content with Google. Thanks in advance!