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 

HELP! Apex Syntax Errors and Coding Issues

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". 

Now, I've tried this code that someone else gave me:
<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>

But every time I try to run it I keep getting a syntax error that says:

"Error: Unknown property 'Service_Request__cStandardController.serviceRequest'"

What do I do about this? Do I need to create a custom controller in the Developer Console? And if so, how do I begin to do that?? Any help would be greatly appreciated! Thank you very much!

Matt
Best Answer chosen by Matt Rich 7
kaustav goswamikaustav goswami
Hi Matt,

If I understand you problm correctly then you are trying to show the city and state information of the Store in the list view and detail pages of the Servoce Request custom object. I would suggest that you implement these through Formula fields. Do not go for visualforce page and controller.

Create two formula fields that will traverse the look up relationship and show the city and state information.
The formula for the fields should look something like this - Store_Number__r.City__c.

If this does not help you you then please let me know. If you have to do it with code then please paste the controller as well.

As for the snippet you have pasted above the main problem is with this line - 
<apex:outPutText value={!serviceRequest}/>
You have used the standard controller. You do not have any reference to the custom controller.
The compiler is looking for a property called serviceRequest in the standrdController but will not be able to get anything like this. Not sure why you have that property included in your code.
If my understanding is correct then please implement this through formula fields.

Thanks,
Kaustav
 

All Answers

kaustav goswamikaustav goswami
Hi Matt,

If I understand you problm correctly then you are trying to show the city and state information of the Store in the list view and detail pages of the Servoce Request custom object. I would suggest that you implement these through Formula fields. Do not go for visualforce page and controller.

Create two formula fields that will traverse the look up relationship and show the city and state information.
The formula for the fields should look something like this - Store_Number__r.City__c.

If this does not help you you then please let me know. If you have to do it with code then please paste the controller as well.

As for the snippet you have pasted above the main problem is with this line - 
<apex:outPutText value={!serviceRequest}/>
You have used the standard controller. You do not have any reference to the custom controller.
The compiler is looking for a property called serviceRequest in the standrdController but will not be able to get anything like this. Not sure why you have that property included in your code.
If my understanding is correct then please implement this through formula fields.

Thanks,
Kaustav
 
This was selected as the best answer
Matt Rich 7Matt Rich 7
Kaustav,

I tried formula fields in the beginning and had no luck, but the formula you gave me worked like a charm! I can't believe how easy it was. Why didn't I think of that in the first place? Haha! Thank you so much for your help... you were able to help me where no one else could! Great job!!!

Thanks again,

Matt