0

I have two object temp__c and NFSave___c. I am dumping all the data in temp object through data loader in rich text area field(Section__c). Then I am sending the data with apex class from Section field to NFSave object fields as per the column position.

I am not able to perform upsert as duplicate records are adding in NFSave object. I have mark SSN__c field from NFSave object as external id. Please help as I am stuck here from so long.

global class NJImport implements Database.Batchable<sObject>{    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select Section__c from temp__c';
    
        return Database.getQueryLocator(query);
    }
        
    global void execute(Database.BatchableContext BC, List<temp__c> accList){
        String textImportSection;
        List< NFSave___c > list = new List< NFSave___c>();
         
        for(NFSave___c Import : accList){
            textImportSection =  Import.Section__c;
            if(textImportSection != null && textImportSection != ''){
                NFSave___c Obj = new NFSave___c();
                Obj.PAAD_SSN__c = textImportSection.mid(0,9);
                list.add(Obj); 
            }
        }
    
        upsert list;
    }

1 Answer 1

1

The issue is in for(NFSave___c Import : accList). You are looping in accList, so type should be temp__c

global void execute(Database.BatchableContext BC, List<temp__c> accList){

 String textImportSection;
 List< NFSave___c > list = new List< NFSave___c>();
 
 for(temp__c Import : accList){         
     textImportSection =  Import.Section__c;
     if(textImportSection !=null && textImportSection !=''){
       NFSave___c Obj = new NFSave___c();
       Obj.PAAD_SSN__c = textImportSection.mid(0,9);
       list.add(Obj); 
 }
}

upsert list;

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .