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
Sainath VenkatSainath Venkat 

VF page to display child records on Parent object

How to create a VF page that will display child records on parent by grouping text field on child.

I have a text field status__c on child object, I want to group records based on that field.

for example,
Status__c = 1
record1
record2

Status__c = 2
record1
record2
record3

like this I want to show on VF page on parent record
PriyaPriya (Salesforce Developers) 

Hi Sainath, 

Can you elaborate little more about your requirement and 

Are these record 1, record2 parent recod or child object record?

Regards,

Priya Ranjan

Sainath VenkatSainath Venkat
Hello Priya

thanks for helping me out in this issue

Those are child records, on parent related list I want to display child records group by status__c value, on display also I want to show records by status__c
PriyaPriya (Salesforce Developers) 
Hi Sainath,

I have written the below prototype code for you. Here we are defininf the Map which contain the Status as key and the records which has that status as Values. You will have to render this Map on your related list. 
You can use this sample code and modify as per your requirement.
 
Map<childObjectStatus , List<childObject>>> childObjMap;
			 for(childObject cObj:[Select id, name, status from childObject]){
				if(!childObjMap.keyset().contains(cObj.status)){
					List<childObject>> cList;
				
					cList.add(cObj);
					childObjMap.put(cObj.status, cObj)
				}else{
				
				List<childObject>> cList;
				
					cList = childObjMap.get(childObject.status);
				cList.add(cObj);
				childObjMap.put(childObject.status, cList)
				}
				
			 
			 }

Please mark it as the Best Answer so that it can help others in the future.

Regards,

Priya Ranjan



 
Sainath VenkatSainath Venkat
@priya Ranjan

can you help me with sample vf code how to render map values,

On vf page, I want status value nd those those records which contains status value should visible