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
johncusackjrjohncusackjr 

Input Field for Queries

Hi,

 

I'm trying to implement a custom search screen for a custom object based on fields.

 

And i'm planning to use inputField to get the field query. inputField should display correct widget based on the type  (if it's  date, date picker, if a user lookup user selector etc.) But it does not display anything for read only fields (like Last Modified Date etc.). What might be the reason and also how can I implement this?

 

Thanks,

John

Best Answer chosen by Admin (Salesforce Developers) 
Hengky IlawanHengky Ilawan

Hi,

 

I didn't mean that you have to create any new fields, but to just 'borrow' the field from other object (or any unused field of  same type in the same object)

 

Eg. I use the StartDateTime field from Event object so the VF page will generate a corresponding date time widget.

 

// controller
public Event ev {get; set;}

List<CustomObject__c> objs = [
    SELECT .. FROM CustomObject__c
    WHERE LastModifiedDate = :ev.StartDateTime];


<!-- VP Page -->
<apex:pageBlock >
    <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Last Modified Date" for="lastModifiedDate"></apex:outputLabel>
            <apex:inputField value="{!ev.StartDateTime}" id="lastModifiedDate"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>
              

 -Hengky-

All Answers

Hengky IlawanHengky Ilawan

Hi,

 

The obvious reason is because it's a read only field.

Workaround is to use another date/datetime field in your custom object (or any object that have the same custom field type) for the page to generate the corresponding widget, and then just 'map' the inputted value to the Last Modified Date field in the query.

 

-Hengky-

johncusackjrjohncusackjr

Thanks but this does not solve the issue. Because customer will be allowed to add custom fields and search based on those also. And those fields might be read only also and managing and filtering those newly created fields is another headache. So, creating widgets by ourselves is the only way for now.

 

John

Hengky IlawanHengky Ilawan

Hi,

 

I didn't mean that you have to create any new fields, but to just 'borrow' the field from other object (or any unused field of  same type in the same object)

 

Eg. I use the StartDateTime field from Event object so the VF page will generate a corresponding date time widget.

 

// controller
public Event ev {get; set;}

List<CustomObject__c> objs = [
    SELECT .. FROM CustomObject__c
    WHERE LastModifiedDate = :ev.StartDateTime];


<!-- VP Page -->
<apex:pageBlock >
    <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Last Modified Date" for="lastModifiedDate"></apex:outputLabel>
            <apex:inputField value="{!ev.StartDateTime}" id="lastModifiedDate"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>
              

 -Hengky-

This was selected as the best answer
colemabcolemab

You might be interested in looking at the code for the component that I created that does a similar task.  I have added pick list and look-up support but haven't added support for a date picker yet. 

 

However, you can pass in an object and it will dynamically display all filterable fields with appropriate options.  Much like the list view filter screen or the report filter screen.

 

The blog post can be found here and has a link to the code which is on git hub.

johncusackjrjohncusackjr

Thanks for the information. This will be very useful but datepicker is also important. Actually Salesforce should have a new component like inputField that supports searching/filtering via it.

 

John