1

I have the below code where the Set and list is of same type Call2_vod__c , a custom object in salesforce but still throws subject error in that line. Can some one help me here?

Apex class:

global class AckCallUpdatenew implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id,Name,Account_vod__c,Call_Date_vod__c FROM Call2_vod__c where ESR_Call__c=null and Recordtype.Name like \'%Sample%\' and Status_vod__c = \'Submitted_vod\'';
        return Database.getQueryLocator(query);
    }

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

    List<Call2_vod__c> AckCall= 
            [SELECT  Ack_For_Call_abv__c  
                      FROM Call2_vod__c
                     where  recordtype.Name like '%Acknowledge%'];

   // Set<Id> resultIds = (new Map<Id,Call2_vod__c>(AckCall)).keySet();    
    Set<Call2_vod__c> s1 = new Set<Call2_vod__c>(AckCall);             
         for(Call2_vod__c a : scope)
         {
           If(!s1.contains(a.Name))
           {
                  if(a.ESR_Call__c==false && a.Call_Date_vod__c+90<date.today())
                   {
                    a.Unlock_vod__c=true;
                    a.ESR_Call__c=true;
                    }


           }
              update a;
         }
             }   

    global void finish(Database.BatchableContext BC) {
    }

 }
1

A Set<Call2_Vod__c> can't lookup a String (which you're trying to do by a.Name). You'd have to make a map based like Map<String, Call2_Vod__c>, or a Set<String> of names that exist.

You'll probably want to change your execute method to look like this:

Set<String> names = new Set<String>();
for(Call2_Vod__c record:scope) {
    names.add(record.Name);
}
for(Call2_Vod__c record:[SELECT Name FROM Call2_Vod__c WHERE recordType.Name LIKE '%Acknowledge%') {
    names.remove(record.Name);
}
for(Call2_Vod__c record:scope) {
    if(!names.contains(record.Name) && !record.ESR_Call__c && record.Call_Date_Vod__c.addDays(90)<System.Today()) {
        record.Unlock_Vod__c = record.ESR_Call__c = true;
    }
}
update scope;

While I don't know exactly what your intent is, this should probably get you closer to where you want to be.

Also note how I moved the update outside the loop. You shouldn't perform DML operations in a loop, even in a batch process, to avoid errors.

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