0

I have two custom objects: 'MRC Cases' (parent) and 'MRC Case Notes' (child). On the MRC Cases Lightning Record Page I want to display all of the case notes associated with the MRC Case, with the full text of each note visible without clicking through to each note record individually.

If I just drop in a related lists widget on a Lightning Record Page, the standard view truncates long fields and requires a separate click through to each record to view the full notes.

I'm trying to create a VF page that displays the full notes. I was able to create a working page using the standard controller for the Case Notes (child) object, but then realized I can't add that to the MRC Cases record page because it has to use the standard controller for parent object and would need a custom controller or extension to access the related records.

I'm stuck writing the controller. (note: the API names for the two objects are "Grievance__c" (MRC Cases) and "Grievance_Note__c" (MRC Case Notes))

Here's what I have:

MrcCaseList.vfp:

<apex:page standardController="Grievance__c" extensions="MrcCaseListController" recordSetVar="notes" sidebar="false" >     
      <apex:pageBlock >
        <apex:pageBlockTable value="{!notes}" var="n">
                <apex:column headerValue="Case Note" value="{!n.Note__c}" style="width: 76%; padding:10px;vertical-align:top;" />            

                <apex:column value="{!n.Contact_Date__c}" style="width: 6%; padding:10px; vertical-align:top;"/> 

                <apex:column value="{!n.Contact_Type__c}" style="width: 6%; padding:10px; vertical-align:top;"/>

                <apex:column value="{!n.CreatedById}" style="width: 6%; padding:10px; vertical-align:top;"/>    
                <apex:column style="width: 6%; padding:10px;vertical-align:top;">
                    <apex:outputLink value="/{!n.id}" target="_blank">
                        {!n.Note_Created_Date_Time__c}
                    </apex:outputLink>
                </apex:column>   
        </apex:pageBlockTable>
  </apex:pageBlock>  

</apex:page>

MrcCaseListController.apxc:

public with sharing class MrcCaseListController {     

    public List<Grievance_Note__c> notes{get;set;} 
    public Grievance__c mrcCase {get;set;} 

    public MrcCaseListController(ApexPages.StandardController controller) { 

        mrcCase = (Grievance__c)controller.getRecord();      

        List <Grievance__c> mrcCaseList = [SELECT id FROM Grievance__c WHERE id =: mrcCase.id LIMIT 1]; 

        notes = [SELECT id,Note__c,Note_Created_Date_Time__c,Contact_Date__c,Grievance__c,Contact_Type__c,CreatedById,LastModifiedById 
                    FROM Grievance_Note__c 
                    WHERE Grievance__c = :mrcCase.id 
                    ORDER BY Note_Created_Date_Time__c];  

} 

}

I'm getting this error from the VF page:

Unknown constructor 'MrcCaseListController.MrcCaseListController(ApexPages.StandardSetController controller)'

Why do I get this error? How can I fix it?

0

The problem is you are attempting to use a StandardListController where in this case not needed. For your controller this should be ok.

public with sharing class MrcCaseListController {

    private final Grievance__c mcrCase;

    public MrcCaseListController(ApexPages.StandardController stdController) {
        this.mcrCase = (Grievance__c)stdController.getRecord();
    }

    public List<Grievance_Note__c> getNotes() {
        return [
            SELECT  Id,
                    Note__c,
                    Note_Created_Date_Time__c,
                    Contact_Date__c,
                    Grievance__c,
                    Contact_Type__c,
                    CreatedById,
                    LastModifiedById
            FROM    Grievance_Note__c
            WHERE   Grievance__c = :mrcCase.id
            ORDER   BY Note_Created_Date_Time__c
        ];
    }
}

Then for the VisualForce page you can remove the recordSetVar parameter.

<apex:page standardController="Grievance__c" extensions="MrcCaseListController" sidebar="false">
    <apex:pageBlock>
        <apex:pageBlockTable value="{!notes}" var="n">
            <apex:column headerValue="Case Note" value="{!n.Note__c}" style="width: 76%; padding:10px;vertical-align:top;" />
            <apex:column value="{!n.Contact_Date__c}" style="width: 6%; padding:10px; vertical-align:top;" />
            <apex:column value="{!n.Contact_Type__c}" style="width: 6%; padding:10px; vertical-align:top;" />
            <apex:column value="{!n.CreatedById}" style="width: 6%; padding:10px; vertical-align:top;" />
            <apex:column style="width: 6%; padding:10px;vertical-align:top;">
                <apex:outputLink value="/{!n.id}" target="_blank">
                    {!n.Note_Created_Date_Time__c}
                </apex:outputLink>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
  • Thank you! That worked perfectly – Sarah Feb 21 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.