1

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.

enter image description here

1
  • Any one can suggest me how to fix the issue????
    – fsales572
    Commented Mar 10, 2015 at 9:49

1 Answer 1

0

Which role is the important one for you? You have to make a decision. I would say you should sort out the records from the second list based on the records from the first list. I think the records you are listing are from the same sObject type. For that you can use NOT IN condition. So then you can do the following with a SOQL:

// First list
// Defining a set where all ID's from the list1 are collected
Set<Id> userIdsFromTheFirstList = new Set<Id>
// Collecting the users for the first list
list1 = [Select User__c, User__r.Name From FirstObject__c];
// Now collecting the ID's from all selected users. 
// It will be used in the second SOQL query
for(FirstObject__c entry : list1){
    userIdsFromTheFirstList.add(entry.User__c);
}

// Second list
// Here using the NOT IN condition.
// It means, get all users BUT not the ones that were already selected in the list1
list2 = [Select User__r.Name From SecondObject__c
         Where User__c NOT IN :userIdsFromTheFirstList];
1
  • Thanks for the reply, i have to check this condition.............
    – fsales572
    Commented Mar 10, 2015 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .