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
Michele ToscanoMichele Toscano 

List has duplicate ids and too many SoQL queries, 'Set' is not an iterable object type, and cannot participate in s DML how can I proceed with what I'm trying to do?

I've already tried using Set instead of list but it has a problem with the DML (Update) I reverted my code back which is working but then has 'duplicate ids' and too many SOQL queries...I've even tried using another Map- but there was an issue with the update. Maybe my syntax was off??  Please help.

global class Batch_ExpDate_PricIn implements Database.Batchable<sObject>,Database.Stateful
   global Database.QueryLocator start(Database.BatchableContext BC)
        string manualExpStr = 'Manually Expired'; //Correct Status -11/2/16 MT
        string expiredStr = 'Expired'; 

       //Modify query - remove nested subquery -11/2/16 MT
        string query= 'select Id,RecordTypeId,RecordType.Name,Par_Status__c,Effective_date__c,Expiration_Date__c from Price_Authorization_Request__c where Par_Status__c !=:manualExpStr and Par_Status__c !=:expiredStr';
             return Database.getQueryLocator(query);

   global void execute(Database.BatchableContext BC, List<Price_Authorization_Request__c> Parlist) {
       if(Parlist != null && !Parlist.isEmpty())
           Map<String,string> maprecTypewithId = new Map<String,String>();
           List<Price_Authorization_Request__c> listPARToUpdate = new List<Price_Authorization_Request__c>();
           for(RecordType rec : [select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c']) 
       Map<Id, Integer> childRecCount= new Map<id, Integer>();
       Map<Id, Integer> updatedCount= new Map<Id, Integer>();
       Set<Id> prI= new Set<Id>();
       for(Price_Authorization_Request__c parObj : Parlist){ 
      childRecCount.put(parObj.Id, 0);
      updatedCount.put(parObj.Id, 0);
       List<Pricing_Input__c> pInput= [select Id,Expiration_Date_Change_To__c,Effective_date__c, Price_Authorization_Request__c from Pricing_Input__c WHERE Price_Authorization_Request__c IN :prI];  
       //get original count 
       for(Pricing_Input__c pi :pInput){
                childRecCount.put(pi.Price_Authorization_Request__c, childRecCount.get(pi.Price_Authorization_Request__c)+1); 
             if(pi.Expiration_Date_Change_To__c != null && pi.Expiration_Date_Change_To__c < {  
          updatedCount.put(pi.Price_Authorization_Request__c,  //only consider the updated count -11/3/16 MT
        for(Price_Authorization_Request__c parObj : Parlist){
        if( (childRecCount.get(parObj.Id) == updatedCount.get(parObj.Id) && childRecCount.get(parObj.Id) > 0) || (parObj.Expiration_Date__c < && childRecCount.get(parObj.Id) == 0)){ //consider # of childRecs on OR evaluation; -11/14/16 MT 
          parObj.Par_Status__c = 'Expired'; 
          if(parObj.RecordType.Name == 'Standard PAR' && maprecTypewithId.get('ReadOnlyStandard PAR') != null)
                      parObj.RecordTypeId = maprecTypewithId.get('ReadOnlyStandard PAR');
                    else if(parObj.RecordType.Name == 'Formula PAR' && maprecTypewithId.get('ReadOnlyFormula PAR') != null)
                      parObj.RecordTypeId = maprecTypewithId.get('ReadOnlyFormula PAR');
               update listPARToUpdate;
    global void finish(Database.BatchableContext BC)