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
roni shoreroni shore 

Display comma separated values

Hi Guys - I have written a controller which is being used in an vf component. My issue is I need to display adresses comma seperated.
pls suggest 

controller
------------
public with sharing class DisplayList{ 
    public List<Address__c> Records {get; set;} 
    
    public DisplayList(){ 
    Records = [SELECT Name 
               FROM Address__c
               WHERE Billing_Account__c = :ApexPages.currentPage().getParameters().get('Id')];
    system.debug('record-->'+Records); 
    } 
 }
vf component snippet
=----------------------------
 </apex:repeat>
        <apex:repeat value="{!Records}" var="Record">
         <div><span>Service Addresses:</span><span><apex:outputText value="{!Record.Name}" escape="false"/></span></div>
    </apex:repeat>
 
Best Answer chosen by roni shore
GauravendraGauravendra
Hi Roni,

If you want to display the addresses seperated by comma in single line then refer the below code:
VF Page:
<apex:repeat value="{!Records}" var="Record">
		  <span> <apex:outputText value="{!Record.Name}" /> </span>
			{!IF(mapadd[Record] == siz,'',',') }
 </apex:repeat>
Apex Code:
public with sharing class DisplayList{ 
    public List<Address__c> Records {get; set;} 
    public Map<Address__c,Integer> mapadd{get;set;}
	public Integer siz {get;set;}
    public Integer count;
	
    public DisplayList(){ 
	mapadd = new Map<Address__c, Integer>();
    Records = [SELECT Name 
               FROM Address__c
               WHERE Billing_Account__c = :ApexPages.currentPage().getParameters().get('Id')];
	siz = Records.size();
	count =0;
	for(Address__c a : Records) {
		count++;
		mapadd.put(a,count);
		
	}
			   
    } 
 }

Hope this helps.

All Answers

GauravendraGauravendra
Hi Roni,

If you want to display the addresses seperated by comma in single line then refer the below code:
VF Page:
<apex:repeat value="{!Records}" var="Record">
		  <span> <apex:outputText value="{!Record.Name}" /> </span>
			{!IF(mapadd[Record] == siz,'',',') }
 </apex:repeat>
Apex Code:
public with sharing class DisplayList{ 
    public List<Address__c> Records {get; set;} 
    public Map<Address__c,Integer> mapadd{get;set;}
	public Integer siz {get;set;}
    public Integer count;
	
    public DisplayList(){ 
	mapadd = new Map<Address__c, Integer>();
    Records = [SELECT Name 
               FROM Address__c
               WHERE Billing_Account__c = :ApexPages.currentPage().getParameters().get('Id')];
	siz = Records.size();
	count =0;
	for(Address__c a : Records) {
		count++;
		mapadd.put(a,count);
		
	}
			   
    } 
 }

Hope this helps.
This was selected as the best answer
roni shoreroni shore
Awesome Thanks for Help :)