0

Need help to create vf page where i want to display list of cases on case record page, created by same contact of current case. Also it will based on 2 custom fields values(i.e. product & Component). Based on these 3 fields i want make vf page and display it under case record page.

i have created vf page and controller but not sure how to proceed with criteria.

vf page:

<apex:page standardController="Case" recordSetVar="c" extensions="caselistcontroller">
<apex:pageBlock >
    <apex:pageBlockTable value="{!c}" var="cs">
        <apex:column value="{!cs.CaseNumber}"/>
        <apex:column value="{!cs.Products__c}"/>
       <apex:column value="{!cs.ContactId}"/>
    </apex:pageBlockTable>
</apex:pageBlock>

Controller:

for controller till the point to fetch contact id from case i have written logic.

public class caselistcontroller 
    {
    public Contact con{get;set;}
    public Case caseObject{get;set;}

      public caselistcontroller(ApexPages.StandardsetController controller)
        {
            con = new Contact();
            caseObject = new case();
            caseObject = (Case)controller.getRecord();
            //Get the Currently logged in community user contact id
            String cntId = [SELECT Id, ContactId, Name FROM User WHERE Id =: UserInfo.getUserId()].ContactId;
            caseObject.ContactId = cntId;
        }

    }

Can any one guide me in right direction. That would be helpful.

Case record page where contact and product is blank. enter image description here

0

Below controller should help you

public class caselistcontroller { 
    public Case caseObject{get;set;}
    public List<Case> casesWithSameContacts {get;set;}
    public Case tCase {get;set;}
    public caselistcontroller(ApexPages.StandardController controller) { 
        caseObject = (Case)controller.getRecord(); 
        tCase = [Select Id, ContactId from Case where ID=: caseObject.Id];
        casesWithSameContacts = new List<Case>();
        casesWithSameContacts = [select id, CaseNumber,Products__c,ContactId from Case where ContactId =: tCase.ContactId and Id !=:caseObject.Id];
    }
}

And your visualforce page should be

<apex:page standardController="Case" extensions="caselistcontroller">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockTable value="{!casesWithSameContacts}" var="cs">
                <apex:column value="{!cs.CaseNumber}"/>
                <apex:column value="{!cs.Products__c}"/>
               <apex:column value="{!cs.ContactId}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Only change I had done is to query on other cases which had the same contact Id as the current case. And removed recordSetVar from visualforce page.

  • I have tried the above code, it is giving me error as "Unexpected token 'caseObject.Id'." – Admin Feb 11 at 7:28
  • Forgot to add colon ":" in SOQL query. Updated the answer – Vijay Ganji Feb 11 at 7:47
  • Hi Vijay, i can see case list on record page but this list is having contact name and product as blank. i want to display list of cases whose contact id is same as current case record page. i have added snap into question for your reference. – Admin Feb 11 at 8:03
  • If that is what your requirement is, then I updated the answer, this updated answer should work for you. – Vijay Ganji Feb 11 at 8:11
  • i have tried the same thing but it didn't work. i have checked in debug logs it is not picking up current case's id. could you please help me with that – Admin Feb 11 at 8:20

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.