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
Mats ErikssonMats Eriksson 

Custom VF Page on Case Layout, does it work?

I have created a VF Page that uses the case standard controller plus a custom made controller that returns a recordset that I can iterate through and render nicely on the VFP.

 

The page is to be embedded in a Case Page Layout.

 

Now, I want to grab the custom serial number from the case in question and pass it to my controller to be used in the WHERE part of my SOQL query. I figure I should be able to use the <apex:variable> mechanism and pick it up in the controller but I can't save the page because it can't find my custom serial number. Does the VFP live in it's own bubble, blissfully ignorant of the case in context? Or can I somehow traverse the page collection to get to the case page and lift the serial number from it?

 

In the page:

<apex:variable var="srchText" value="{!MySerial_Number__c}"/>

In the Controller:
strSerial = System.currentPageReference().getParameters().get('MySerial_Number__c');

The error comes when trying to save the page. Error message is Error: Unknown property 'CaseStandardController.MySerial_Number__c'

 

What to do?

 

/Mats 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

If it were me, I'd simply create a list of related cases via a SOQL query in the constructor (based on the record in the standard controller).  Then I'd expose these as a controller property and output a datatable based on it.

 

Something like the following:

 

Controller:

 

public MyController
{
   public List<Case> related {get; set;}

   public MyController(ApexPages.StandardController std)
   {
      Case cs=(Case) standardController.getRecord();
      related=[select id, Name from Case 
               where MySerial_Number__c=:cs.MySerial_Number__c
               and id!=:cs.id];
   }
}

 Page:

<apex:datatable value="{!related}" var="rel">
   <apex:column value="{!var.id}"/>
   <apex:column value="{!var.Name}"/>
</apex:datatable>

 

All Answers

bob_buzzardbob_buzzard

As you are using the standard controller, the case record will be automatically populated and available to your extension controller or page.  You can pull in additional fields by including them in the page but not rendering.

 

E.g. Page:

 

<apex:page standardcontroller="Case" extensions="myController">
   <apex:outputText value="{!Case.MySerial_Number__c}" rendered="false"/>
</apex:page>

 Controller:

 

public class MyExtension
{
   public MyExtension (ApexPages.StandardController std)
   {
      Case cs=(Case) std.getRecord();
      String serial=cs.MySerial_Number__c;
   }
}

 

Mats ErikssonMats Eriksson

Thank You Bob!

 

I saw something like that in this post (http://boards.developerforce.com/t5/Visualforce-Development/error-referencing-field-using-standard-controller-extension/m-p/83237) and tried it before. I will try it again as per your instructions.

 

To test it properly I need to insert the page into the case page layout. Unfortunately the page is not available in my page layout editor. I thought it would automatically be availabe if you used a standard object as your controller? (at an early stage it WAS available there but a lot of water has run under the bridge since)

 

My page uses a Custom List Controller but references Cases (plus my own extension) and not the standard one, is that why it's not beeing available? I used the information here to build the controller: http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_compref_pageBlock.htm|StartTopic=Content%2Fpages_compref_pageBlock.htm|SkinName=webhelp

 

 

/Mats

 

bob_buzzardbob_buzzard

If you don't use the standard cases controller you won't be able to add the page into the record detail view I'm afraid.  Only pages with the standard controller appear in the layout editor.  

 

Once you have it on the page, you are guaranteed to be able to get the record from the standard controller.

 

 

Mats ErikssonMats Eriksson

I thought I WAS using the standard case controller, I am after all referencing it:

<apex:page standardController="Case" recordSetvar="cases" extensions="DuplicateSerials" standardStylesheets="true">

 

/Mats

Mats ErikssonMats Eriksson

This is what screws things up: recordSetvar="cases"

 

As soon as I changed the page to use recordsets it got disqualified from appearing on case page layouts. Unfortunately, it does not show up under the Related Lists section in the editor instead. That would have been neat.

 

How do you create your own related lists?

 

/Mats

bob_buzzardbob_buzzard

You are using the standard set controller, due to the recordSetVar attribute, which is different - it deals with a collection of cases rather than one.

bob_buzzardbob_buzzard

Cross post!

 

Can you clarify what you are trying to do?  I'm a little confused now.

Mats ErikssonMats Eriksson

If YOU are confused, imagine me! :P

 

What I want to do is the following.

 

When the case officers here take ownership of a new case arriving from the SSP, I want them to be aware of any prior cases filed on the same serial number. Ideally by presenting them with a list of cases that contain the samt serial number when they open the case.

 

If I can't pass a recordset across, can I pass any other object across that can be parsed and/or iterated through as 5-6 columns by n rows in the client?

 

/Mats

 

 

bob_buzzardbob_buzzard

If it were me, I'd simply create a list of related cases via a SOQL query in the constructor (based on the record in the standard controller).  Then I'd expose these as a controller property and output a datatable based on it.

 

Something like the following:

 

Controller:

 

public MyController
{
   public List<Case> related {get; set;}

   public MyController(ApexPages.StandardController std)
   {
      Case cs=(Case) standardController.getRecord();
      related=[select id, Name from Case 
               where MySerial_Number__c=:cs.MySerial_Number__c
               and id!=:cs.id];
   }
}

 Page:

<apex:datatable value="{!related}" var="rel">
   <apex:column value="{!var.id}"/>
   <apex:column value="{!var.Name}"/>
</apex:datatable>

 

This was selected as the best answer
Mats ErikssonMats Eriksson

 

Thank you Bob!

 

You are a rock in an unruly sea of doubts, minunderstandings and (my) lack of knowledge! :)

 

That did the trick, it works like a charm!

 

With some tweaks and changes it turned out like below.

 

Page:

<apex:page StandardController="Case"  extensions="DuplicateSerials" standardStylesheets="true">
    <apex:pageBlock title="Duplicate Serial Numbers!"  />
    <apex:form >
	    <apex:outputText value="{!Case.Serial_Number__c}" rendered="false"/>
		<apex:datatable value="{!related}" var="rel" width="80%">
			<apex:column headervalue="Case Number">
				<apex:outputLink value="/{!rel.Id}" target="_blank">{!rel.casenumber}</apex:outputLink>
	        </apex:column>
			<apex:column headervalue="Subject">
	             <apex:outputLink value="/{!rel.Id}" target="_blank">{!rel.subject}</apex:outputLink>
			</apex:column> 
			<apex:column headervalue="Case Actions" Value="{!rel.Case_Actions__c}"/>
			<apex:column headervalue="Serial Number" Value="{!rel.Serial_Number__c}"/>
			<apex:column headervalue="Case Status" Value="{!rel.status}"/>
		</apex:datatable>   
    </apex:form>
</apex:page>

 

Controller:

 

public with sharing class DuplicateSerials {
	public List<Case> related {get; set;}	
    public DuplicateSerials(ApexPages.StandardController std) {   	
		Case cs=(Case) std.getRecord();
		related=[select id, CaseNumber, Serial_Number__c,  Subject, Case_Actions__c, Status  from Case where                      Serial_Number__c =:cs.Serial_Number__c ];
		}
}

 

 

/Mats