+ Start a Discussion
Gowkanapalli JanardhanreddyGowkanapalli Janardhanreddy 

how to avoid duplicate record in page block table based owner name in return statement in controller?

how to avoid dupliacte records based on owner name , and not show dupliacte owners in page block table .
can any one help me 
pconpcon
Can you give a little bit more clarification (and possibly some existing code) to what you are trying to do?  A screenshot or mockup of what you expect the data to show on the page with some sample source data (with field names) would be very useful.

NOTE: Please use the "Add a code sample" button (icon <>) to add code to increase readability and to make it easier to reference.
Gowkanapalli JanardhanreddyGowkanapalli Janardhanreddy
public list<musqot__Allocation_amount__c > getperentmembers(){
  Return [Select musqot__Costcentre__r.musqot__cc_Owner__c,Costcentre__r.name,Costcentre__r.musqot__Email__c from musqot__Allocation_amount__c where Costcentre__c <> null and musqot__To_Plan__c =:workId limit 100];

vf page code:

<apex:pageBlockTable value="{!perentmembers}" var="pmi" columnsWidth="200,200,100,*" rendered="{!IF(perentmembers.size>0,true,false)}"> <!--<apex:column value="{!pmi.Costcentre__r.name}" headerValue="{!$Label.mem_Cost_center}" rendered="{!Level2}" /> --> <apex:column value="{!pmi.Costcentre__r.cc_Owner__c}" headerValue="{!$Label.mem_Name}" /> <apex:column value="{!pmi.Costcentre__r.Email__c}" headerValue="{!$Label.mem_Email}"/> <apex:column headerValue="{!$Label.mem_Role}" title="{!pmi.Costcentre__r.name}" >CC Owner</apex:column> </apex:pageBlockTable> </apex:pageBlock>

ouput
:
 User-added image

Hi Pcon,
this is my code am fetching different object records and displyaing on vf page. here user name same but records are diffferent , so dont want to display duplicate username ,i want only one user name .can giveme suggestion for this how to approach this task.


 
pconpcon
This should do what you are looking for.  What I am doing is making a new local class to store your member information and then filtering them based on email.  If the email is in the map, but the name is null or empty, then we'll overwrite it when the new one in hopes it has a better name.

VisualForce Controller
 
public class AllocationMembers {
    public String name;
    public String email;
    public String role;

    public AllocationMember(musqot__Allocation_amount__c member) {
        this.name = member.musqot__Costcentre__r.musquot__cc_Owner__c;
        this.email = Costcentre__r.musqot__Email__c;
        this.role = 'CC Owner';
    }
}

Map<String, AllocationMembers> memberMap = null;

public List<AllocationMembers> getPerentMembers() {
    if (memberMap != null) {
        return memberMap.values();
    }

    Map<String, AllocationMembers> memberMap = new Map<String, AllocationMembers>();

    for (musqot__Allocation_amount__c member: [
        select musqot__Costcentre__r.musqot__cc_Owner__c,
            Costcentre__r.name,
            Costcentre__r.musqot__Email__c
        from musqot__Allocation_amount__c
        where Costcentre__c != null and
            musqot__To_Plan__c = :workId
        limit 100
    ]) {   
        String email = Costcentre__r.musqot__Email__c;

        if (email == null) {
            continue;
        }

        if (
            !memberMap.containsKey(email) ||
            (
                memberMap.get(email).name == null ||
                memberMap.get(email).name.trim() == ''
            )
        ) { 
            memberMap.put(email, new AllocationMembers(member));
        }
    }  

    return memberMap.values();
}

public Boolean getHasPerentMembers() {
    return !getPerentMember.isEmpty();
}

VisualForce Code
 
<apex:pageBlockTable value="{!perentmembers}" var="pmi" columnsWidth="200,200,100,*" rendered="{!hasPerentMembers}">
    <apex:column value="{!pmi.name}" headerValue="{!$Label.mem_Name}" />
    <apex:column value="{!pmi.email}" headerValue="{!$Label.mem_Email}" />
    <apex:column value="{!pmi.role}" headerValue="{!$Label.mem_Role}" />
</apex:pageBlockTable>

NOTE: This code has not been tested and may contain typographical or logical errors.