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
Sri 7Sri 7 

i am getting this error at running the batch class First error: Duplicate id in list: a2v8E00000037ZgQAI

global class ZuoraProductRatePlanChargeHandlerBatch implements Database.Batchable<sObject>
{    
    global Database.QueryLocator start(Database.BatchableContext BC){
        system.debug('ProductRatePlanCharge');        
        String query = 'select id,Invoice_Display_Name__c,(select id,Name,Subscription_Product_Charge__c,Subscription_Product_Charge__r.Zuora__SubscriptionRatePlan__c,Subscription_Product_Charge__r.Zuora__SubscriptionRatePlan__r.PRPC_Invoice_Display_Name__c from Product_Users__r where Subscription_Product_Charge__r.Zuora__SubscriptionRatePlan__r.PRPC_Invoice_Display_Name__c!=null) from zqu__ProductRatePlanCharge__c where Invoice_Display_Name__c!=null';
        return database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext Bc, List<zqu__ProductRatePlanCharge__c> prpcList){
        Set<Zuora__SubscriptionRatePlan__c> srplist = new Set<Zuora__SubscriptionRatePlan__c>();
        for(zqu__ProductRatePlanCharge__c each:prpcList){
            if(each.Product_Users__r !=null){
                List<SPG_Product_User__c> tempUsers = each.Product_Users__r;
                for(SPG_Product_User__c eachUser:tempUsers){
                    if(eachUser.Subscription_Product_Charge__c!=null){
                        if(eachUser.Subscription_Product_Charge__r.Zuora__SubscriptionRatePlan__c!=null){
                            if(each.Invoice_Display_Name__c!=eachUser.Subscription_Product_Charge__r.Zuora__SubscriptionRatePlan__r.PRPC_Invoice_Display_Name__c){
                                Zuora__SubscriptionRatePlan__c tempSRP = new Zuora__SubscriptionRatePlan__c();
                                tempSRP.Id=eachUser.Subscription_Product_Charge__r.Zuora__SubscriptionRatePlan__c;
                                tempSRP.PRPC_Invoice_Display_Name__c = each.Invoice_Display_Name__c;
                                srplist.add(tempSRP);
                            }                         
                        }
                    }                    
                }
            }            
        }
        if(srplist.size() >0 ){
            List<Zuora__SubscriptionRatePlan__c> tempList = new List<Zuora__SubscriptionRatePlan__c>();
            tempList.addAll(srplist);
            update tempList;
        }        
    }
    global void finish(Database.BatchableContext BC){        
    }
}
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sri,

Greetings to you!

You are getting the Duplicate id in list error because you have a Duplicate id in your list.
 
The list won't give you a problem when you add a duplicate to the list, but it will give you a problem during run-time when it actually finds duplicates during an update to the list.

A Map won't allow for a duplicate to be entered, to begin with.

Lists can hold duplicate values, but if it contains duplicate sobject IDs and you try to update you'll get the error.
1. Create a map of  <id,sobject>
2. Convert the list to Map so that the duplicate IDs are removed.
3. Update the values part of the Map. 

Please refer to the below link which might help you further with the above issue.

https://help.salesforce.com/articleView?id=000257270&language=en_US&type=1

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas