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
Matt Rich 7Matt Rich 7 

Can I add a VF page to a list view?

Is there a way to embed a Visualforce page into a list view? Let me explain what I have done so far:

I have created a custom object within Salesforce called "Service Requests". Within the "Service Requests" object I have created a custom field called "Store Number". "Store Number" is a lookup relationship field that is related to another custom object called "Stores". When a service request is made we always include the store number so that we can tell which store needs service done. For instance, Service Request 0006 is for store number 2368. Now, if we use our mouse to hover over the store number, 2368, then we will see a hover detail window telling us that the store is located in East Stroudsburg, PA. But my client doesn't want to have to hover over the store number every time to see the location of the store. So, I have created a Visualforce page which references the store's location. Here is my code:


<apex:page standardController="Service_Request__c"> {!Service_Request__c.Store_Number__r.City__c}, {!Service_Request__c.Store_Number__r.State__c}</apex:page>

Using this code I am able to auto populate the store's location by referencing the custom fields, "City" and "State", which are found in the custom object "Stores". However, my client wants to be able to go into the "Service Requests" tab and, under the list views, he wants to see not only the "Request Number" (0006) and "Store Number" (2368) but also the city and state of the store (which would be related to the Store Number). But when I go to edit the list views I don't see the VF page in "Available Fields", so I can't move it over into "Selected Fields". What should I do here? Any help would be greatly appreciated! Thank you!
Ajay K DubediAjay K Dubedi
Hi Matt, you can show a visual force page in a list view in many ways which apex provide to you like apex:pageBlockTable, apex:repeat apex:dataTable.

Usage: 1st Method
 
<apex:pagestandardController="Service_Request__c" recordSetVar="s">
    <apex:repeat value="{!s}" var="c">
        <apex:outputText value="{!Service_Request__c.Store_Number__r.City__c}"/>
        <apex:outputText value={!Service_Request__c.Store_Number__r.State__c}"/>
        <apex:outPutText value={!serviceRequest}/>
        <!--Add the fields which you want to show in thw list-->
    </apex:repeat>
</apex:page>

Usage: 2nd Method
<apex:pagestandardController="Service_Request__c" recordSetVar="s">
<apex:pageBlock>
    <apex:PageBlockTabel value="{!s}" var="c">
      <apex:column>
          <apex:outputText value="{!Service_Request__c.Store_Number__r.City__c}"/>
      </apex:column>
      <apex:column>
          <apex:outputText value={!Service_Request__c.Store_Number__r.State__c}"/>
      </apex:column>
        <apex:column>
          <apex:outPutText value={!serviceRequest}/>
      </apex:column>
        <!--Add the fields which you want to show in thw list-->
    </apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Please let me know if this helps


 
Matt Rich 7Matt Rich 7
Thank you for your reply Ajay! I have one question, I tried the code you provided and I am getting a syntax error which is reading:

"Error: Unknown property 'Service_Request__cStandardController.serviceRequest'"

I don't know what to do about this. Do you understand what this means?

Thank you very much for your help!