0

I have created a Batch class and write a logic into execute method. In this logic I queried a Object (DuplicateRecordItem) . It's giving an error on saving the batch class Error:(sObject type 'DuplicateRecordItem' is not supported). I can not understand why this showing. My logic is below Please Help!

global void execute(Database.BatchableContext BC, List<DuplicateRecordSet> scope) {

    //call MergeAccounts method.
    MergeAccounts(scope); 
}  

public static void  MergeAccounts(List<DuplicateRecordSet> dupset){

    Map<Id, DuplicateRecordSet> mapDuplicateRecordSet =  new Map<Id,DuplicateRecordSet>();

    for(DuplicateRecordSet drs : dupset){
        mapDuplicateRecordSet.put(drs.Id, drs);
    }

    Map<Id, Set<Id>> mapDuplicateRecordItem =  new Map<Id, Set<Id>>();

    //here throwing error 
    for(DuplicateRecordItem drI : [SELECT Id,RecordId, DuplicateRecordSetId FROM DuplicateRecordItem where DuplicateRecordSetId In : mapDuplicateRecordSet.keyset()]){

        if(!mapDuplicateRecordItem.containskey(drI.DuplicateRecordSetId)){
            mapDuplicateRecordItem.put(drI.DuplicateRecordSetId, new Set<Id>{drI.RecordId}); 
        }
        else{
            mapDuplicateRecordItem.get(drI.DuplicateRecordSetId).add(drI.RecordId); 
        }
    } 

    for(DuplicateRecordSet dr : [SELECT Id FROM DuplicateRecordSet where Id IN : mapDuplicateRecordItem.keyset()]){

        Set<Id>  setaccId =  mapDuplicateRecordItem.get(dr.Id);

        list<id> lstAccId = new list<id>(); 

        for(Account acc : [SELECT Id, name,BillingCountry, BillingState FROM Account where ID In : setaccId And OwnerId ='00540000002lBne' Limit 1]){

                setaccId.remove(acc.Id);  
                lstAccId.addAll(setaccId);  
                merge acc lstAccId;
                break; 
            } 
        }  
} 
1

Make sure that your class is saved at API version 32.0 or above, DuplicateRecordItem did not come in until version 32.0.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.