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
Oliver Freeman 9Oliver Freeman 9 

Visualforce Page for Cases for Same Asset

Hello,

I'm trying to create a VF page which will appear on the Case page layout displaying all other cases for the asset on that particular case - here's what I have done so far:

- Created custom formula field on the Case Object for the AssetId (Asset_ID__c)
- Created an Apex Class:
public class CaseRelatedCasesExtension {

    public CaseRelatedCasesExtension(ApexPages.StandardController controller) {

    }


    public list<Case> cases {get;set;}

    public CaseRelatedCasesExtension(){
        cases  = [select id, assetid, accountid, CaseNumber, OwnerId from case Where Asset.Id='AssetId'];
    }
}
- Created a Visualforce Page:
<apex:page standardController="Case" extensions="CaseRelatedCasesExtension">
    <apex:form >
        <apex:pageBlock >
            Case Related Emails
                <apex:PageBlockTable value="{!case}" var="case">
                    <apex:column width="10%">
                        <apex:commandLink value="View" onclick="window.open('/{!case.Id}');"/>
                    </apex:column>
                    <apex:column width="80%" value="{!case.Subject}" />
                    <apex:column width="10%" value="{!case.CaseNumber}"/>
                </apex:pageBlockTable>
        </apex:pageBlock>  
    </apex:form>
</apex:page>

Currently, all that this is showing is the current case, not all cases for that asset.

Sorry if I'm just being an idiot, I'm very new to Apex Classes and Visualforce!

Thanks,
Oli
Best Answer chosen by Oliver Freeman 9
Oliver Freeman 9Oliver Freeman 9
Found some info here: https://developer.salesforce.com/forums/?id=906F0000000AukMIAS

Very helpful! Resolved the issues I was experiencing. 

All Answers

Oliver Freeman 9Oliver Freeman 9
Sorry, my Apex Class is as follows:
public class CaseRelatedCasesExtension {

    public CaseRelatedCasesExtension(ApexPages.StandardController controller) {

    }


    public list<Case> cases {get;set;}

    public CaseRelatedCasesExtension(){
        cases  = [select id, assetid, accountid, CaseNumber, OwnerId from case Where Asset_ID__c='AssetId'];
    }
}

 
Oliver Freeman 9Oliver Freeman 9
Found some info here: https://developer.salesforce.com/forums/?id=906F0000000AukMIAS

Very helpful! Resolved the issues I was experiencing. 
This was selected as the best answer