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
nikita dhamalnikita dhamal 

passing distinct value of records to vf page

i have a cloumn KOLTitleRole in my visualforce page in which i get duplicate values. i have modified the code but still getting duplicates... where am i going wrong?please help...
i have attached my  code below
vf page:
 <apex:pageBlockTable value="{!KOLTitleRole}" var="v"  style="width:100px;">
    <apex:column headerValue="KOL - Title/ Role">
    <apex:outputLink value="/{!v.id}" target="_blank" style="text-decoration:none;">
    <apex:facet name="Header">KOL-Title/ Role</apex:facet>
    <div style="color:white; background-color:{!If(v.Status__c =='Not Needed'||v.name==null,'color:#797d7f','#736F6E')};">
      {!v.KOL_Title__c} </div></apex:outputLink>
    </apex:column> 
    </apex:pageBlockTable>
controller:
public List<Product_EntryStatus__c>getKOLTitleRole()
{
List<Product_EntryStatus__c>dosiersumbitlist;
// dosiersumbitlist= [SELECT Name,Status__c,Country__c,Product__c,KOL_Title__c,Key_Opinion_Leader__c FROM Product_EntryStatus__c where Country__c =: prod.Country__c and Product__c=: prod.Product__c and KOL_Title__c!=null];
List<Product_EntryStatus__c> lstAccount = new List<Product_EntryStatus__c>();
 
Set<String> setKolName = new Set<String>();
 
lstAccount = [select Name,KOL_Title__c from Product_EntryStatus__c where Country__c =: prod.Country__c and Product__c=:prod.Product__c and KOL_Title__c!=null] 
for (Integer i = 0; i< lstAccount.size(); i++)
{
    setkolName.add(lstAccount[i].KOL_Title__c); // contains distict values
    String qs='SELECT Name,Status__c,Country__c,Product__c,KOL_Title__c,Key_Opinion_Leader__c FROM Product_EntryStatus__c where' +Product_EntryStatus__c.KOL_Title__c +'IN :'+setkolName;
    System.debug('Query string is: '+ qs);
    System.debug('****************************************'+setkolName);
 dosiersumbitlist= [SELECT Name,Status__c,Country__c,Product__c,KOL_Title__c,Key_Opinion_Leader__c FROM Product_EntryStatus__c where KOL_Title__c =:setkolName];
}
return dosiersumbitlist;
}
Best Answer chosen by nikita dhamal
Prem Anandh 1Prem Anandh 1
Hi Nikita, 

I have done bit modification on your code. Please refer
 
public List<Product_EntryStatus__c>getKOLTitleRole()
{
	List<Product_EntryStatus__c> dosiersumbitlist = new List<Product_EntryStatus__c>	
	Set<String> setKolName = new Set<String>();
 
	
	for (Product_EntryStatus__c objProductEntryStatus : [select Name,KOL_Title__c from Product_EntryStatus__c where Country__c =: prod.Country__c and Product__c=:prod.Product__c and KOL_Title__c != null])
	{
		if(!setkolName.contains(objProductEntryStatus.KOL_Title__c))
		{
	    	setkolName.add(objProductEntryStatus.KOL_Title__c); // contains distict values	 
	    	dosiersumbitlist.add(objProductEntryStatus);
		}

	}

	return dosiersumbitlist;
}

Please let me know still if you are facing an issue. 

Thanks, 
Prem Anandh