how to avoid duplicate records based on owner role, and not show duplicate usernames in page block table . can any one help me we have multiple member roles(CC owner, member, viewer)based on roles member should be unique in the page block table. Highest priority should be CC owner.
Here is my vf page:
<apex:pageBlock title="Members">
<apex:pageBlockButtons location="top" >
<apex:commandButton value="Addmember" action="{!newMember}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!members}" var="mi" columnsWidth="200,200,100,*">
<apex:column headerValue= Name">
<apex:commandLink value="{!mi.ProjUsers__r.name}" action="{!gotoMemberEdit}"><apex:param name="mbrId" value="{!mi.Id}"/>
</apex:commandLink>
<apex:outputText value="{!mi.ProjUsers__r.name}"
</apex:column>
<apex:column value="{!mi.ProjUsers__r.email}" id="text" headerValue="Email"/>
<apex:column value={!mi.Role__c}" headerValue="Role"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!parentmembers}" var="pmi"
<apex:column value="{!pmi.Costcentre__r.cc_Owner__c}" headerValue="Parent"/>
<apex:column value="{!pmi.Costcentre__r.Email__c}" headerValue="Email"/>
<apex:column headerValue="Role" title="{!pmi.Costcentre__r.name}">CC Owner</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
And i had written some logic for above page
Controller:
Public PageReference newmember(){
membs= [Select ProjMembers__c, musqot__Email_del__c ,ProjUsers__c, SubProjMembers__c, Role__c, Type__c, User_Email__c FROM Members__c where ProjMembers__c=:workId limit 1];
PageReference memberobj=new PageReference('/apex/memberobj?planid='+EncodingUtil.urlEncode(workId,'UTF-8'));
memberobj.setredirect(true);
return memberobj;
}
public List<Members__c > getmembers(){
return [Select id, ProjMembers__c, musqot__ProjUsers__r.email ,ProjUsers__c,ProjUsers__r.name, SubProjMembers__c, Role__c, Type__c FROM Members__c where ProjMembers__c=:workId AND SubProjMembers__c=null];
}
public list<musqot__Allocation_amount__c > getparentmembers(){
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];
}
For reference i have added screenshot below According to screenshot record owner only show in the first pageblock table. Suppose i change the record owner previous owner should be member in the record, at the same time he is also cc owner in the second pageblock table then display cc owner role in the second pageblock table and hide member in the first pageblock table.