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
vijendahr kvijendahr k 

fetch distinct records from the list of records employee id and based on its related modifed date.

Hello all, 

 could you please help me get all the distinct records basaed  on changed by(Emp id)  and changed on fie( datetime) ,below is query 
list<Contact_Audit__c> aulitList =[SELECT Name, Changed_By_Name__c, Contact_ID__c, Changed_By__c, Changed_On__c, Change_Type__c FROM Contact_Audit__c where Contact_ID__c = 'xxxxxxx']

in this query Changed_On__c is list of employess emp1, emp2, emp3..
Change_Type__c captures last modifed by records, but i need a distinct record of employee based on recent last modified by records Example
emp1 ------- 01
emp1 ------- 02
emp1 ------- 03
emp2 ------- 01
emp2 ------- 02
emp2 ------- 03
emp3 ------- 01
emp3 ------- 02
emp3 ------- 03

in this list i need only records like
emp1 ------- 01
emp2 ------- 01
emp3 ------- 01

Can any one tel me how to get distinct records based on employee and his changged type(dateTime) using salesforce or some method. 
Please suggest me correct way

Best Answer chosen by vijendahr k
Raj VakatiRaj Vakati
Hi Vijaya, You have to write apex logic to get such result.Please refer sample code here and try some thing similar 
List<Contact_Audit__c> lst= [select id,name from Contact_Audit__c where name in :sArr ];

 Map<String,Contact_Audit__c> mapStrByzip=new Map<String,Contact_Audit__c>();

for(Contact_Audit__c ls:lst){
    mapStrByLstzips.put(zipone.Name,ls);//This is map and hence it will always have unique values