You need to sign in to do that
Don't have an account?
sivapriyaa maniam sivakumar
Duplicate value display in VisualForce Page
Hi,
Can anyone please tell me the solution for duplicate value display in VisualForce page.
The SOQL query retrieve the correct output.But in VisualForce page ,it display the N-number of times of same output.
SOQL Output:
VisualForce Page Output:(It display more than one times)
Apex Controller:
VisualForcePage
Thanks,
Sivapriyaa M S
Can anyone please tell me the solution for duplicate value display in VisualForce page.
The SOQL query retrieve the correct output.But in VisualForce page ,it display the N-number of times of same output.
SOQL Output:
VisualForce Page Output:(It display more than one times)
Apex Controller:
public with sharing class CollegeCourseClassic { Public List <CSM_Courses_By_Colleges__c> courses{get;set;} // the soql without the order and limit private String soql {get;set;} // the collection of contacts to display public List<String> listOfCourseName {get;set;} public List<String> listCollegeName {get;set;} public List<String> listDistrictName {get;set;} // the current sort direction. defaults to asc public string college{get;set;} public string course{get;set;} public string state{get;set;} public string level{get;set;} public string district{get;set;} // the current field to sort by. defaults to last name // format the soql for display on the visualforce page public String debugSoql { get { return soql + 'limit 100'; } set; } // init the controller and display some sample data when the page loads public CollegeCourseClassic() { listOfCourseName = new List<String>(); listCollegeName = new List<String>(); listDistrictName = new List<String>(); for(CSM_Courses_By_Colleges__c courseName: [select id,name from ICSM_Courses_By_Colleges__c ]) listOfCourseName.add(courseName.name); for(CSM_COLLEGES__C clgname: [select id,College_Name__c from CSM_COLLEGES__C limit:500]) listCollegeName.add(clgname.College_Name__c); for(CSM_COLLEGES__C distName: [select id, District__c from CSM_COLLEGES__C]) listDistrictName.add(distName.District__c); soql = 'Select id,name,College_UGC_Id__r.College_UGC_Id__c,College_UGC_Id__r.state__c,College_UGC_Id__r.College_Name__c,College_UGC_Id__r.District__c,College_UGC_Id__r.Name,College_UGC_Id__r.City_Town__c ,Course_Level__c,Degree_Conferred__c,Department__c,Student_Intake__c From CSM_Courses_By_Colleges__c'; runQuery(); } // runs the actual query public void runQuery() { try { System.debug(soql); courses = Database.query(soql +' limit 100'); } catch (Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'+e)); } } // runs the search with parameters passed via Javascript public void search_method() { soql = 'Select id,name,College_UGC_Id__r.College_UGC_Id__c,College_UGC_Id__r.state__c,College_UGC_Id__r.College_Name__c,College_UGC_Id__r.District__c,College_UGC_Id__r.Name,College_UGC_Id__r.City_Town__c ,Course_Level__c,Degree_Conferred__c,Department__c,Student_Intake__c From CSM_Courses_By_Colleges__c where College_UGC_Id__r.College_Name__c != null'; if (!college.equals('')) System.debug('college'+college); soql += ' and College_UGC_Id__r.College_Name__c LIKE \''+String.escapeSingleQuotes(college)+'%\''; if (!course.equals('')) soql += ' and name LIKE \''+String.escapeSingleQuotes(course)+'%\''; if (!district.equals('')) soql += ' and College_UGC_Id__r.District__c LIKE \''+String.escapeSingleQuotes(district)+'%\''; if (!level.equals('select')) soql += ' and Course_Level__c LIKE \''+String.escapeSingleQuotes(level)+'%\''; if (!state.equals('selectst')) soql += ' and College_UGC_Id__r.state__c LIKE \''+String.escapeSingleQuotes(State)+'%\''; // run the query again runQuery(); } public List<SelectOption> getcourselevel() { list<selectoption> options = new list<selectoption>(); Schema.DescribeFieldResult fieldResult = CSM_COURSES_BY_COLLEGES__c.Course_Level__c.getDescribe(); list<schema.picklistentry> values = fieldResult.getPickListValues(); options.add(new SelectOption('select','--Select Course Level--')); for (Schema.PicklistEntry a : values) { options.add(new SelectOption(a.getLabel(), a.getValue())); } return options; } public List<selectoption> getStates() { list<selectoption> options = new list<selectoption>(); Schema.DescribeFieldResult fieldResult = CSM_COLLEGES__c.State__c.getDescribe(); list<schema.picklistentry> values = fieldResult.getPickListValues(); options.add(new SelectOption('selectst','--Select State--')); for (Schema.PicklistEntry a : values) { options.add(new SelectOption(a.getLabel(), a.getValue())); } return options; } }
VisualForcePage
<apex:page controller="CollegeCourseClassic" title="College Courses" sidebar="false" docType="html-5.0"> <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" /> <apex:includeScript value="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js" /> <apex:stylesheet value="{!URLFOR($Resource.SLDS0120, 'assets/styles/salesforce-lightning-design-system-vf.css')}" /> <apex:stylesheet value="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"/> <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <apex:form > <script> function ChangeMode(mode){ if(mode=='Awardees'){ document.getElementById('awardees').style.display = 'block'; document.getElementById('applicants').style.display = 'none'; initAwardeesTableSearch(); ApplicantsTableSearhDestroy(); } if(mode=='Applicants'){ document.getElementById('awardees').style.display = 'none'; document.getElementById('applicants').style.display = 'block'; initApplicantsTableSearch(); AwardeesTableSearchDestroy(); } quickSearch("text-input-01"); } </script> <style> #header{ font-size:24px !important; text-align:center; margin-bottom:16px; margin-top:16px; } .filterlist{ width: 16%; float:right; font-size: 16px; margin-left: 1px; margin-right: 20px; } .orgnamefilter{ width: 25%; float:right; font-size: 16px; margin-right: 10px; margin-left: 10px; } .orgnamefilter1{ width: 25%; float:right; font-size: 16px; margin-right: 10px; margin-left: 200px; } .issueArealist { width: 15%; margin-right: 450px; } .issueArealist1 { width: 15%; margin-right: 100px; } .profilelisting{ width:97%; margin-left:1%; margin-right:3%; } .profilelisting td{ vertical-align:middle !important; font-size:12px; } .tablecontainer{ position:relative; top:20px; } #select-01{ height:36px; line-height:36px; cursor: pointer; } #select-issue-area{ height:36px; line-height:36px; cursor: pointer; } .buttonclass{ font-size:12px; } .logo{ width:50px; margin-right:10px; } .redbutton{ background-color:#89211B !important; white-space:nowrap; border-style:none !important; font-weight:normal !important; } .yellowbutton{ background-color:#FAA418 !important; white-space:nowrap; color:#89211B !important; border-style:none !important; font-weight:normal !important; } .orangebutton{ background-color:#F15323 !important; border-style:none !important; font-weight:normal !important; } .btn:hover{ opacity:0.8; } .link{color:#89211B !important;} .link:hover{color:#F15323 !important;} .slds img { max-width: none !important; } .fa-star { color: #8C1D04; } .center{text-align:center;} </style> <script type="text/javascript"> function changeMe(sel) { sel.style.color = "#000"; } </script> <!-- REQUIRED SLDS WRAPPER --> <div class="slds" style="margin-bottom:100px"> <div id="header"> Find Colleges and Courses </div> <table> <tr> <td > <apex:inputText id="text-input-01" list="{!listCollegeName}" value="{!college}" html-placeholder="Enter College Name" /></td> <td > <apex:inputText id="text-input-02" list="{!listOfCourseName}" value="{!course}" html-placeholder="Enter Course Name"/> </td> <td > <apex:selectList value="{!level}" size="1"> <apex:selectOptions value="{!courselevel}" /> </apex:selectList> </td> <td > <apex:selectList value="{!state}" size="1"> <apex:selectOptions value="{!States}" /> </apex:selectList></td> <td> <apex:inputText id="select-01" list="{!listDistrictName}" value="{!district}" html-placeholder="Enter District"/> </td> <td > <apex:commandButton value="Go!" action="{!search_method}" /></td> </tr> </table> <apex:outputPanel title=""> <apex:pageMessages ></apex:pageMessages> </apex:outputPanel> <div id="awardees" width="95%" class="tablecontainer"> <table id="awardeesTable" class="slds-table slds-table--bordered profilelisting" cellpadding="3px !important"> <thead> <tr class="slds-text-heading--label"> <th onclick="simulateTHclick('1');" colspan="1" class="slds-is-sortable" scope="col" width="12%"> College Name <button class="slds-button slds-button--icon-bare"> <svg aria-hidden="true" class="slds-button__icon slds-button__icon--small"> <use xlink:href="{!URLFOR($Resource.SLDS0120, '/assets/icons/utility-sprite/svg/symbols.svg#arrowdown')}"></use> </svg> <span class="slds-assistive-text">Sort</span> </button> </th> <th width="10%" onclick="simulateTHclick('3');" class="slds-is-sortable slds-cell-wrap" scope="col">Distict <button class="slds-button slds-button--icon-bare"> <svg aria-hidden="true" class="slds-button__icon slds-button__icon--small"> <use xlink:href="{!URLFOR($Resource.SLDS0120, '/assets/icons/utility-sprite/svg/symbols.svg#arrowdown')}"></use> </svg> <span class="slds-assistive-text">Sort</span> </button> </th> <th onclick="simulateTHclick('4');" width="10%" class="slds-is-sortable slds-cell-wrap" scope="col"> <apex:outputtext value="State" id="LastPublished"/> <button class="slds-button slds-button--icon-bare"> <svg aria-hidden="true" class="slds-button__icon slds-button__icon--small"> <use xlink:href="{!URLFOR($Resource.SLDS0120, '/assets/icons/utility-sprite/svg/symbols.svg#arrowdown')}"></use> </svg> <span class="slds-assistive-text">Sort</span> </button> </th> </tr> <tr style="display:none;"> <th column-valueAwd="0" scope="col"> </th> <th column-valueAwd="1" scope="col"> </th> <th column-valueAwd="2" scope="col"> </th> </tr> </thead> <tbody> <!--LIST OUT ALL THE colleges and courses--> <!-- COllege Name with State and District --> <apex:repeat value="{!courses}" var="ccourse" > <tr > <td class="slds-cell-wrap"> {!ccourse.College_UGC_Id__r.College_Name__c} </td> <td class="slds-cell-shrink"> {!ccourse.College_UGC_Id__r.District__c}</td> <td class="slds-cell-shrink"> {!ccourse.College_UGC_Id__r.state__c}</td> <!-- <td class="slds-cell-wrap"> {!ccourse.CSM_Courses_By_Colleges__c.Name}</td> --> </tr> <tr> <td colspan ="3"> <!-- List of Course display under college --> <table id="coursesTable" class="slds-table slds-table--bordered profilelisting" cellpadding="3px !important"> <apex:repeat value="{!courses}" var="cont"> <tr> <td class="slds-cell-wrap"> {!cont.Name}</td> <td class="slds-cell-wrap"> {!cont.Course_Level__c}</td> <td class="slds-cell-shrink"> {!cont.Degree_Conferred__c}</td> <td class="slds-cell-shrink"> {!cont.Department__c}</td> <td class="slds-cell-shrink">{!cont.Student_Intake__c}</td> </tr> </apex:repeat> </table> </td> </tr> </apex:repeat> </tbody> </table> </div> </div> </apex:form> </html> </apex:page>
Thanks,
Sivapriyaa M S
Query is proper but VF page code is wrong. If you properly look into the above code <apex:repeat value="{!courses}" var="cont"> inside <apex:repeat value="{!courses}" var="ccourse" > , both are using {!courses} value which is making duplicate. Right now you have 6 records so 6*6 combo of duplicates will appear.
You should modify your code so that outer apex:repeat is having College_UGC_Id__c record and inner apex:repeat should have courses belonging to the outer College_UGC_Id__c record. Go for wrapper class or map with lists.
Thanks for your reply.
I tried the map and wrapper class ,but it is not shown the correct result please suggest the any other solution.
thx